2025-01-02 22:44:20 +08:00
2024-12-31 18:02:40 +08:00
2025-01-01 23:04:09 -08:00
2024-12-31 18:02:40 +08:00
2024-12-31 18:02:40 +08:00
2025-01-01 21:01:05 -08:00
2025-01-01 22:14:58 -08:00
2025-01-01 22:14:58 -08:00
2025-01-01 22:14:58 -08:00
2024-12-31 18:02:40 +08:00
2025-01-02 22:44:20 +08:00
2025-01-01 22:14:58 -08:00
2025-01-02 22:44:20 +08:00
2025-01-02 22:44:20 +08:00
2025-01-01 21:01:05 -08:00

UPP - your app

Usage

usage present

app := upp.New()

app.With(db, es, api)

app.Run(ctx)

simple example

var config = struct {
	ES string
}{}

func init() {
	flag.StringVar(&config.ES, "es", "http://es.dev:9200", "")

	flag.Parse()

	tool.TablePrinter(config)
}

type Record struct {
	Id        uint64 `json:"id" gorm:"primaryKey;column:id"`
	CreatedAt int64  `json:"created_at" gorm:"column:created_at;autoCreateTime:milli"`
	Name      string `json:"name" gorm:"column:name"`
}

func main() {
	app := upp.New(upp.Config{Debug: false})

	app.With(upp.InitDB("sqlite://data.db", &Record{}))
	app.With(upp.InitApi(api.New()))

	app.With(upp.InitFn(func(u interfaces.Upp) {
		u.UseLogger().Debug("[init] create init record")
		u.UseDB().Create(&Record{Name: "init"})
	}))

	app.GET("/hello/:name", func(c *api.Ctx) error {
		name := c.Param("name")
		c.UseLogger().Debug("[hello] got name = %s", name)
		record := &Record{Name: name}
		err := c.UseDB().Create(record).Error
		return c.JSON(map[string]any{"record": record, "err": err})
	})

	app.RunSignal()
}


run with env

DEBUG=true go run . 

DEBUG=true LISTEN_HTTP=0.0.0.0:8080 go run .
Description
No description provided
Readme 166 KiB
Languages
Go 100%