Example #1
0
func handleConfigGet(ctx *cli.Context, cfg *config.Config) error {
	key := ctx.Args().First()
	value, err := cfg.String(key)
	if err != nil {
		return ExitCode{
			BadArgs,
			fmt.Sprintf("Could not retrieve %s: %v", key, err),
		}
	}
	fmt.Println(value)
	return nil
}
Example #2
0
func NewKit(c *cli.Context, conf *config.Config) *Kit {
	co, err := conf.Get(c.String("config"))
	co.Env() // parse environ variables
	Must(err)

	// set up gin
	if !co.UBool("debug") {
		gin.SetMode(gin.ReleaseMode)
	}

	return &Kit{
		Conf: co,
	}
}
Example #3
0
func handleConfigSet(ctx *cli.Context, cfg *config.Config) error {
	key := ctx.Args().First()
	value := ctx.Args().Get(1)
	if err := cfg.Set(key, value); err != nil {
		return ExitCode{
			BadArgs,
			fmt.Sprintf("Could not set %s: %v", key, err),
		}
	}

	folder := repo.GuessFolder()
	if _, err := repoconfig.SaveConfig(filepath.Join(folder, ".brig", "config"), cfg); err != nil {
		return ExitCode{
			UnknownError,
			fmt.Sprintf("Could not save config: %v", err),
		}
	}
	return nil
}
Example #4
0
func initIntoGlobal(folder string, cfg *yamlConfig.Config) error {
	globalRepo, err := global.New()
	if err != nil {
		return err
	}

	ipfsSwarmPort, err := globalRepo.NextIPFSSwarmPort()
	if err != nil {
		return err
	}

	daemonPort, err := globalRepo.NextDaemonPort()
	if err != nil {
		return err
	}

	cfg.Set("ipfs.swarmport", ipfsSwarmPort)
	cfg.Set("daemon.port", daemonPort)

	log.Debugf(
		"Using ports: %d (ipfs-swarm) %d (brigd)",
		ipfsSwarmPort, daemonPort,
	)

	err = globalRepo.AddRepo(global.RepoListEntry{
		RepoPath:      folder,
		DaemonPort:    daemonPort,
		IpfsSwarmPort: ipfsSwarmPort,
	})

	if err != nil {
		return err
	}

	return nil
}
Example #5
0
File: sql.go Project: yzzyx/fsw
func (sc *SqlCollector) SetConfig(cfg *config.Config) (err error) {

	if sc.driver, err = cfg.String("driver"); err != nil {
		return err
	}

	if sc.datasource, err = cfg.String("datasource"); err != nil {
		return err
	}

	if sc.query, err = cfg.String("query"); err != nil {
		return err
	}

	sc.interval = cfg.UInt("interval", 3600)
	return nil
}
Example #6
0
func session(config *config.Config) (s sessions.Store, err error) {

	secret := []byte(config.UString("secret", "go-default-secret"))
	t := config.UString("type", "cookie")

	switch t {
	case "cookie":
		s = sessions.NewCookieStore(secret)
	case "redis":
		s, err = sessions.NewRedisStore(
			config.UInt("size"),
			config.UString("network"),
			config.UString("address"),
			config.UString("password"),
			secret,
		)
	default:
		err = errors.New("No session type allowed.")
	}

	if err != nil {
		return nil, err
	}

	o, _ := config.Get("options")

	if o != nil {
		s.Options(sessions.Options{
			Path:     o.UString("path"),
			Domain:   o.UString("domain"),
			MaxAge:   o.UInt("max_age", int(30*time.Minute)),
			Secure:   o.UBool("secure"),
			HttpOnly: o.UBool("http_only"),
		})
	}

	return s, nil
}