Beispiel #1
0
func runServer(c *cli.Context) {
	kit := utils.NewKit(c, conf)
	kit.Engine = gin.Default()

	kit.Engine.StaticFS("/static", &assetfs.AssetFS{
		Asset:    data.Asset,
		AssetDir: data.AssetDir,
		Prefix:   "static",
	})

	kit.Engine.Use(func(c *gin.Context) {
		c.Set("kit", kit)
	})

	// Avoid favicon react handling
	kit.Engine.GET("/favicon.ico", func(c *gin.Context) {
		c.Redirect(301, "/static/images/favicon.ico")
	})

	kit.Engine.GET("/api/v1/conf", api.ConfHandler)

	kit.Engine.Use(func(c *gin.Context) {
		id, _ := uuid.NewV4()
		c.Set("uuid", id)
	})
	react.Bind(kit)
	utils.Must(kit.Engine.Run(":" + kit.Conf.UString("port")))
}
Beispiel #2
0
func (config FlagsConfig) ApplyTo(cmd string, c *cli.Context) error {
	entry := config[""]
	if cmd != "" {
		entry.Apply(config[cmd])
	}
	vars := entry.Vars()
	if cmd == "" {
		vars["local"] = vars["global"]
		vars["global"] = nil
	}
	for key, val := range vars["global"] {
		if !c.GlobalIsSet(key) {
			switch val.(type) {
			case string:
				strVal := val.(string)
				if strVal == "" {
					continue
				}
				c.GlobalSet(key, strVal)
			case []string:
				strSlice := val.([]string)
				if len(strSlice) == 0 {
					continue
				}
				for _, valBit := range strSlice {
					c.GlobalSet(key, valBit)
				}
			default:
				return fmt.Errorf(`unknown value type %T (%s: %+v)`, val, key, val)
			}
		}
	}
	for key, val := range vars["local"] {
		if !c.IsSet(key) {
			switch val.(type) {
			case string:
				strVal := val.(string)
				if strVal == "" {
					continue
				}
				c.Set(key, strVal)
			case []string:
				strSlice := val.([]string)
				if len(strSlice) == 0 {
					continue
				}
				for _, valBit := range strSlice {
					c.Set(key, valBit)
				}
			default:
				return fmt.Errorf(`unknown value type %T (%s: %+v)`, val, key, val)
			}
		}
	}
	return nil
}