示例#1
0
文件: main.go 项目: tmaiaroto/discfg
func main() {
	// If not set for some reason, use us-east-1 by default.
	if discfgDBRegion == "" {
		discfgDBRegion = "us-east-1"
	}

	apex.HandleFunc(func(event json.RawMessage, ctx *apex.Context) (interface{}, error) {
		var m message

		if err := json.Unmarshal(event, &m); err != nil {
			return nil, err
		}

		options.Storage.AWS.Region = discfgDBRegion

		if m.Name != "" {
			options.CfgName = m.Name
		}

		var settings map[string]interface{}
		err := json.Unmarshal([]byte(m.Settings), &settings)
		if err != nil {
			return nil, err
		}

		resp := commands.UpdateCfg(options, settings)

		return commands.FormatJSONValue(resp), nil
	})
}
示例#2
0
文件: main.go 项目: tmaiaroto/discfg
		Options.CfgName = name
		var settings map[string]interface{}

		switch len(args) {
		case 1:
			if err := json.Unmarshal([]byte(args[0]), &settings); err != nil {
				commands.Out(Options, config.ResponseObject{Action: "update", Error: err.Error()})
			}
			break
		case 2:
			Options.CfgName = args[0]
			if err := json.Unmarshal([]byte(args[0]), &settings); err != nil {
				commands.Out(Options, config.ResponseObject{Action: "update", Error: err.Error()})
			}
		}
		resp := commands.UpdateCfg(Options, settings)
		commands.Out(Options, resp)
	},
}
var infoCmd = &cobra.Command{
	Use:   "info",
	Short: "config information",
	Long:  `Information about the config including version and modified time`,
	Run: func(cmd *cobra.Command, args []string) {
		setOptsFromArgs(args)
		resp := commands.Info(Options)
		commands.Out(Options, resp)
	},
}

var setCmd = &cobra.Command{