Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(461)

Side by Side Diff: common/tsmon/config.go

Issue 2225933003: tsmon: read hostname and region from config file (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-go@master
Patch Set: Fixed error in test Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | common/tsmon/config_test.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The LUCI Authors. All rights reserved. 1 // Copyright 2015 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package tsmon 5 package tsmon
6 6
7 import ( 7 import (
8 "encoding/json" 8 "encoding/json"
9 "os" 9 "os"
10 "runtime" 10 "runtime"
11 ) 11 )
12 12
13 // config is the representation of a tsmon JSON config file. 13 // config is the representation of a tsmon JSON config file.
14 type config struct { 14 type config struct {
15 Endpoint string `json:"endpoint"` 15 Endpoint string `json:"endpoint"`
16 Credentials string `json:"credentials"` 16 Credentials string `json:"credentials"`
17 AutoGenHostname bool `json:"autogen_hostname"` 17 AutoGenHostname bool `json:"autogen_hostname"`
18 Hostname string `json:"hostname"`
19 Region string `json:"region"`
18 } 20 }
19 21
20 // loadConfig loads a tsmon JSON config from a file. 22 // loadConfig loads a tsmon JSON config from a file.
21 func loadConfig(path string) (config, error) { 23 func loadConfig(path string) (config, error) {
22 var ret config 24 var ret config
23 25
24 file, err := os.Open(path) 26 file, err := os.Open(path)
25 if err != nil { 27 if err != nil {
26 return ret, err 28 return ret, err
27 } 29 }
28 defer file.Close() 30 defer file.Close()
29 31
30 decoder := json.NewDecoder(file) 32 decoder := json.NewDecoder(file)
31 if err = decoder.Decode(&ret); err != nil { 33 if err = decoder.Decode(&ret); err != nil {
32 return ret, err 34 return ret, err
33 } 35 }
34 36
35 return ret, nil 37 return ret, nil
36 } 38 }
37 39
38 func defaultConfigFilePath() string { 40 func defaultConfigFilePath() string {
39 if runtime.GOOS == "windows" { 41 if runtime.GOOS == "windows" {
40 return "C:\\chrome-infra\\ts-mon.json" 42 return "C:\\chrome-infra\\ts-mon.json"
41 } 43 }
42 return "/etc/chrome-infra/ts-mon.json" 44 return "/etc/chrome-infra/ts-mon.json"
43 } 45 }
OLDNEW
« no previous file with comments | « no previous file | common/tsmon/config_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698