@@ -46,16 +46,10 @@ func init() {
4646}
4747
4848func main () {
49- flag .Parse ()
50- // Convinces goflags that we have called Parse() to avoid noisy logs.
51- // Necessary due to https://github.com/golang/glog/commit/65d674618f712aa808a7d0104131b9206fc3d5ad
52- // and us using another flags package.
53- goflag .CommandLine .Parse ([]string {})
54- goflag .Lookup ("logtostderr" ).Value .Set (strconv .FormatBool (* & glogadapt .Logging .ToStderr ))
55- goflag .Lookup ("alsologtostderr" ).Value .Set (strconv .FormatBool (* & glogadapt .Logging .AlsoToStderr ))
56- goflag .Lookup ("v" ).Value .Set (glogadapt .Logging .Verbosity .String ())
57- goflag .Lookup ("stderrthreshold" ).Value .Set (glogadapt .Logging .StderrThreshold .String ())
58- goflag .Lookup ("log_dir" ).Value .Set (glogadapt .Logging .LogDir )
49+ err := initFlags ()
50+ if err != nil {
51+ glog .Fatal (err )
52+ }
5953
6054 var databases []string
6155 if * & exporterConfig .databases != "" {
@@ -76,15 +70,50 @@ func main() {
7670
7771 http .Handle (* & exporterConfig .metricsEndpoint , promhttp .Handler ())
7872 http .HandleFunc ("/status" , func (w http.ResponseWriter , r * http.Request ) {
79- fmt .Fprint (w , "OK" )
73+ _ , err = fmt .Fprint (w , "OK" )
74+ if err != nil {
75+ glog .Error (err )
76+ }
8077 })
8178 http .HandleFunc ("/" , func (w http.ResponseWriter , r * http.Request ) {
8279 http .Error (w , fmt .Sprintf ("Please GET %s" , * & exporterConfig .metricsEndpoint ), http .StatusNotFound )
8380 })
8481
8582 glog .Infof ("Starting exporter at '%s' to read from CouchDB at '%s'" , * & exporterConfig .listenAddress , * & exporterConfig .couchdbURI )
86- err : = http .ListenAndServe (* & exporterConfig .listenAddress , nil )
83+ err = http .ListenAndServe (* & exporterConfig .listenAddress , nil )
8784 if err != nil {
8885 glog .Fatal (err )
8986 }
9087}
88+
89+ func initFlags () error {
90+ flag .Parse ()
91+ // Convinces goflags that we have called Parse() to avoid noisy logs.
92+ // Necessary due to https://github.com/golang/glog/commit/65d674618f712aa808a7d0104131b9206fc3d5ad
93+ // and us using another flags package.
94+ err := goflag .CommandLine .Parse ([]string {})
95+ if err != nil {
96+ return err
97+ }
98+ err = goflag .Lookup ("logtostderr" ).Value .Set (strconv .FormatBool (* & glogadapt .Logging .ToStderr ))
99+ if err != nil {
100+ return err
101+ }
102+ err = goflag .Lookup ("alsologtostderr" ).Value .Set (strconv .FormatBool (* & glogadapt .Logging .AlsoToStderr ))
103+ if err != nil {
104+ return err
105+ }
106+ err = goflag .Lookup ("v" ).Value .Set (glogadapt .Logging .Verbosity .String ())
107+ if err != nil {
108+ return err
109+ }
110+ err = goflag .Lookup ("stderrthreshold" ).Value .Set (glogadapt .Logging .StderrThreshold .String ())
111+ if err != nil {
112+ return err
113+ }
114+ err = goflag .Lookup ("log_dir" ).Value .Set (glogadapt .Logging .LogDir )
115+ if err != nil {
116+ return err
117+ }
118+ return nil
119+ }
0 commit comments