本文整理汇总了Golang中github.com/tsuru/config.GetString函数的典型用法代码示例。如果您正苦于以下问题:Golang GetString函数的具体用法?Golang GetString怎么用?Golang GetString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetString函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: init
func init() {
config.ReadConfigFile("settings.yaml")
//TODO: Error Checking
basePath, _ := config.GetString("TEMPLATES:BASE")
layoutsPath, _ := config.GetString("TEMPLATES:LAYOUTS")
partialsPath, _ := config.GetString("TEMPLATES:PARTIALS")
dir, _ := os.Getwd()
templatesPath = filepath.Join(dir, basePath)
fmt.Printf("Processing templates in %s\n", templatesPath)
if templates == nil {
templates = make(map[string]*template.Template)
}
layouts, err := filepath.Glob(templatesPath + "/" + layoutsPath + "/*")
if err != nil {
log.Fatal(err)
}
partials, err := filepath.Glob(templatesPath + "/" + partialsPath + "/*")
if err != nil {
log.Fatal(err)
}
for _, layout := range layouts {
files := append(partials, layout)
templates[filepath.Base(layout)] = template.Must(template.ParseFiles(files...))
}
UserRepo = user.NewBaseUserRepository()
if _, err := UserRepo.NewUser("jeff", "password"); err != nil {
fmt.Println(err)
}
}
示例2: main
func main() {
dry := flag.Bool("dry", false, "dry-run: does not start the server (for testing purpose)")
configFile := flag.String("config", "/etc/gandalf.conf", "Gandalf configuration file")
gVersion := flag.Bool("version", false, "Print version and exit")
flag.Parse()
if *gVersion {
fmt.Printf("gandalf-webserver version %s\n", version)
return
}
err := config.ReadAndWatchConfigFile(*configFile)
if err != nil {
msg := `Could not find gandalf config file. Searched on %s.
For an example conf check gandalf/etc/gandalf.conf file.\n %s`
log.Panicf(msg, *configFile, err)
}
router := api.SetupRouter()
bind, err := config.GetString("bind")
if err != nil {
var perr error
bind, perr = config.GetString("webserver:port")
if perr != nil {
panic(err)
}
}
if !*dry {
log.Fatal(http.ListenAndServe(bind, router))
}
}
示例3: buildUrl
func buildUrl(command string, params map[string]string) (string, error) {
apiKey, err := config.GetString("iaas:cloudstack:api-key")
if err != nil {
return "", err
}
secretKey, err := config.GetString("iaas:cloudstack:secret-key")
if err != nil {
return "", err
}
params["command"] = command
params["response"] = "json"
params["apiKey"] = apiKey
var sorted_keys []string
for k := range params {
sorted_keys = append(sorted_keys, k)
}
sort.Strings(sorted_keys)
var string_params []string
for _, key := range sorted_keys {
queryStringParam := fmt.Sprintf("%s=%s", key, url.QueryEscape(params[key]))
string_params = append(string_params, queryStringParam)
}
queryString := strings.Join(string_params, "&")
digest := hmac.New(sha1.New, []byte(secretKey))
digest.Write([]byte(strings.ToLower(queryString)))
signature := base64.StdEncoding.EncodeToString(digest.Sum(nil))
cloudstackUrl, err := config.GetString("iaas:cloudstack:url")
if err != nil {
return "", err
}
return fmt.Sprintf("%s?%s&signature=%s", cloudstackUrl, queryString, url.QueryEscape(signature)), nil
}
示例4: sendGrid
func sendGrid() error {
username, uerr := config.GetString("username")
if uerr != nil {
log.Error("Error loading user name")
}
secretkey, serr := config.GetString("secretkey")
if serr != nil {
log.Error("Error loading secretkey")
}
sg := sendgrid.NewSendGridClient(username, secretkey)
message := sendgrid.NewMail()
email, kerr := config.GetString("addto:email")
if kerr != nil {
return kerr
}
message.AddTo(email)
name, kerr := config.GetString("addto:name")
if kerr != nil {
return kerr
}
message.AddToName(name)
message.SetSubject("GoMegam-IoT ")
message.SetText("Welcome to Gomegam IoT Project")
message.SetFrom("[email protected]")
if r := sg.Send(message); r != nil {
return r
}
return nil
}
示例5: start
func (c *container) start() error {
port, err := getPort()
if err != nil {
return err
}
sharedBasedir, _ := config.GetString("docker:sharedfs:hostdir")
sharedMount, _ := config.GetString("docker:sharedfs:mountpoint")
sharedIsolation, _ := config.GetBool("docker:sharedfs:app-isolation")
sharedSalt, _ := config.GetString("docker:sharedfs:salt")
config := docker.HostConfig{}
config.PortBindings = map[docker.Port][]docker.PortBinding{
docker.Port(port + "/tcp"): {{HostIp: "", HostPort: ""}},
docker.Port("22/tcp"): {{HostIp: "", HostPort: ""}},
}
if sharedBasedir != "" && sharedMount != "" {
if sharedIsolation {
var appHostDir string
if sharedSalt != "" {
h := crypto.SHA1.New()
io.WriteString(h, sharedSalt+c.AppName)
appHostDir = fmt.Sprintf("%x", h.Sum(nil))
} else {
appHostDir = c.AppName
}
config.Binds = append(config.Binds, fmt.Sprintf("%s/%s:%s:rw", sharedBasedir, appHostDir, sharedMount))
} else {
config.Binds = append(config.Binds, fmt.Sprintf("%s:%s:rw", sharedBasedir, sharedMount))
}
}
err = dockerCluster().StartContainer(c.ID, &config)
if err != nil {
return err
}
return nil
}
示例6: Queue
func Queue() (monsterqueue.Queue, error) {
queueData.RLock()
if queueData.instance != nil {
defer queueData.RUnlock()
return queueData.instance, nil
}
queueData.RUnlock()
queueData.Lock()
defer queueData.Unlock()
if queueData.instance != nil {
return queueData.instance, nil
}
queueMongoUrl, _ := config.GetString("queue:mongo-url")
if queueMongoUrl == "" {
queueMongoUrl = "localhost:27017"
}
queueMongoDB, _ := config.GetString("queue:mongo-database")
conf := mongodb.QueueConfig{
CollectionPrefix: "tsuru",
Url: queueMongoUrl,
Database: queueMongoDB,
}
var err error
queueData.instance, err = mongodb.NewQueue(conf)
if err != nil {
return nil, fmt.Errorf("could not create queue instance, please check queue:mongo-url and queue:mongo-database config entries. error: %s", err)
}
shutdown.Register(&queueData)
go queueData.instance.ProcessLoop()
return queueData.instance, nil
}
示例7: EnvListForEndpoint
func (conf *Config) EnvListForEndpoint(dockerEndpoint, poolName string) ([]string, error) {
tsuruEndpoint, _ := config.GetString("host")
if !strings.HasPrefix(tsuruEndpoint, "http://") && !strings.HasPrefix(tsuruEndpoint, "https://") {
tsuruEndpoint = "http://" + tsuruEndpoint
}
tsuruEndpoint = strings.TrimRight(tsuruEndpoint, "/") + "/"
endpoint := dockerEndpoint
socket, _ := config.GetString("docker:bs:socket")
if socket != "" {
endpoint = "unix:///var/run/docker.sock"
}
token, err := conf.getToken()
if err != nil {
return nil, err
}
envList := []string{
"DOCKER_ENDPOINT=" + endpoint,
"TSURU_ENDPOINT=" + tsuruEndpoint,
"TSURU_TOKEN=" + token,
"SYSLOG_LISTEN_ADDRESS=udp://0.0.0.0:" + strconv.Itoa(container.BsSysLogPort()),
}
envMap := EnvMap{}
poolEnvMap := PoolEnvMap{}
err = conf.UpdateEnvMaps(envMap, poolEnvMap)
if err != nil {
return nil, err
}
for envName, envValue := range envMap {
envList = append(envList, fmt.Sprintf("%s=%s", envName, envValue))
}
for envName, envValue := range poolEnvMap[poolName] {
envList = append(envList, fmt.Sprintf("%s=%s", envName, envValue))
}
return envList, nil
}
示例8: postnetwork
func postnetwork(container *global.Container, ip string) {
gulpPort, _ := config.GetInt("docker:gulp_port")
url := "http://" + container.SwarmNode + ":" + strconv.Itoa(gulpPort) + "/docker/networks"
log.Info("URL:> %s", url)
bridge, _ := config.GetString("docker:bridge")
gateway, _ := config.GetString("docker:gateway")
data := &global.DockerNetworksInfo{Bridge: bridge, ContainerId: container.ContainerID, IpAddr: ip, Gateway: gateway}
res2B, _ := json.Marshal(data)
req, err := http.NewRequest("POST", url, bytes.NewBuffer(res2B))
req.Header.Set("X-Custom-Header", "myvalue")
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
log.Error("gulpd client was failed : %s", err)
}
defer resp.Body.Close()
log.Info("response Status : %s", resp.Status)
log.Info("response Headers : %s", resp.Header)
body, _ := ioutil.ReadAll(resp.Body)
log.Info("response Body : %s", string(body))
}
示例9: get
func (redismqQFactory) get(name, consumerName string) (*redismqQ, error) {
host, err := config.GetString("redis-queue:host")
if err != nil {
host = "localhost"
}
port, err := config.GetString("redis-queue:port")
if err != nil {
if nport, err := config.GetInt("redis-queue:port"); err != nil {
port = "6379"
} else {
port = fmt.Sprintf("%d", nport)
}
}
password, _ := config.GetString("redis-queue:password")
db, err := config.GetInt("redis-queue:db")
if err != nil {
db = 3
}
queue := redismq.CreateQueue(host, port, password, int64(db), name)
consumer, err := queue.AddConsumer(consumerName)
if err != nil {
return nil, err
}
return &redismqQ{name: name, queue: queue, consumer: consumer}, nil
}
示例10: dial
func (factory *redismqQFactory) dial() (redis.Conn, error) {
host, err := config.GetString("redis-queue:host")
if err != nil {
host = "localhost"
}
port, err := config.GetString("redis-queue:port")
if err != nil {
if nport, err := config.GetInt("redis-queue:port"); err != nil {
port = "6379"
} else {
port = fmt.Sprintf("%d", nport)
}
}
password, _ := config.GetString("redis-queue:password")
db, err := config.GetInt("redis-queue:db")
if err != nil {
db = 3
}
conn, err := redis.Dial("tcp", host+":"+port)
if err != nil {
return nil, err
}
if password != "" {
_, err = conn.Do("AUTH", password)
if err != nil {
return nil, err
}
}
_, err = conn.Do("SELECT", db)
return conn, err
}
示例11: main
func main() {
dry := flag.Bool("dry", false, "dry-run: does not start the server (for testing purpose)")
configFile := flag.String("config", "/etc/gandalf.conf", "Gandalf configuration file")
gVersion := flag.Bool("version", false, "Print version and exit")
flag.Parse()
if *gVersion {
fmt.Printf("gandalf-webserver version %s\n", version)
return
}
log.Printf("Opening config file: %s ...\n", *configFile)
err := config.ReadAndWatchConfigFile(*configFile)
if err != nil {
msg := `Could not open gandalf config file at %s (%s).
For an example, see: gandalf/etc/gandalf.conf
Note that you can specify a different config file with the --config option -- e.g.: --config=./etc/gandalf.conf`
log.Fatalf(msg, *configFile, err)
}
log.Printf("Successfully read config file: %s\n", *configFile)
router := api.SetupRouter()
bind, err := config.GetString("bind")
if err != nil {
var perr error
bind, perr = config.GetString("webserver:port")
if perr != nil {
panic(err)
}
}
if !*dry {
log.Fatal(http.ListenAndServe(bind, router))
}
}
示例12: user
func (c *Container) user() string {
user, err := config.GetString("docker:user")
if err != nil {
user, _ = config.GetString("docker:ssh:user")
}
return user
}
示例13: Run
// Run is the function that starts the collector. The dryMode parameter
// indicates whether the collector should loop forever or not.
//
// It assumes the configuration has already been defined (from a config file or
// memory).
func Run(dryMode bool) {
log.Init()
connString, err := config.GetString("database:url")
if err != nil {
connString = db.DefaultDatabaseURL
}
dbName, err := config.GetString("database:name")
if err != nil {
dbName = db.DefaultDatabaseName
}
fmt.Printf("Using the database %q from the server %q.\n\n", dbName, connString)
if !dryMode {
provisioner, err := config.GetString("provisioner")
if err != nil {
fmt.Println("Warning: configuration didn't declare a provisioner, using default provisioner.")
provisioner = "juju"
}
app.Provisioner, err = provision.Get(provisioner)
if err != nil {
fatal(err)
}
fmt.Printf("Using %q provisioner.\n\n", provisioner)
timer, err := config.GetInt("collector:ticker-time")
if err != nil {
timer = 60
}
ticker := time.Tick(time.Duration(timer) * time.Second)
fmt.Println("tsuru collector agent started...")
collect(ticker)
}
}
示例14: RunAdminServer
// RunAdminServer starts tsuru administrative api
func RunAdminServer(dry bool) {
log.Init()
connString, err := config.GetString("database:url")
if err != nil {
connString = db.DefaultDatabaseURL
}
dbName, err := config.GetString("database:name")
if err != nil {
dbName = db.DefaultDatabaseName
}
fmt.Printf("Using the database %q from the server %q.\n\n", dbName, connString)
if !dry {
provisioner, err := getProvisioner()
if err != nil {
fmt.Printf("Warning: configuration didn't declare a provisioner, using default provisioner.\n")
}
app.Provisioner, err = provision.Get(provisioner)
if err != nil {
fatal(err)
}
fmt.Printf("Using %q provisioner.\n\n", provisioner)
listen, err := config.GetString("admin-listen")
if err != nil {
fatal(err)
}
listener, err := net.Listen("tcp", listen)
if err != nil {
fatal(err)
}
fmt.Printf("tsuru HTTP server listening at %s...\n", listen)
http.Handle("/", m)
fatal(http.Serve(listener, nil))
}
}
示例15: sshCmds
// sshCmds returns the commands needed to start a ssh daemon.
func sshCmds() ([]string, error) {
addKeyCommand, err := config.GetString("docker:ssh:add-key-cmd")
if err != nil {
return nil, err
}
keyFile, err := config.GetString("docker:ssh:public-key")
if err != nil {
if u, err := user.Current(); err == nil {
keyFile = path.Join(u.HomeDir, ".ssh", "id_rsa.pub")
} else {
keyFile = os.ExpandEnv("${HOME}/.ssh/id_rsa.pub")
}
}
f, err := filesystem().Open(keyFile)
if err != nil {
return nil, err
}
defer f.Close()
keyContent, err := ioutil.ReadAll(f)
if err != nil {
return nil, err
}
sshdCommand, err := config.GetString("docker:ssh:sshd-path")
if err != nil {
sshdCommand = "sudo /usr/sbin/sshd"
}
return []string{
fmt.Sprintf("%s %s", addKeyCommand, bytes.TrimSpace(keyContent)),
sshdCommand + " -D",
}, nil
}