2025-03-10 22:41:10 +08:00
2025-03-08 23:05:02 +08:00
2025-03-10 22:41:10 +08:00
2025-03-08 23:05:02 +08:00
2025-03-08 23:05:02 +08:00
2025-03-08 23:05:02 +08:00
2025-03-10 22:41:10 +08:00
2025-03-10 22:41:10 +08:00
2025-03-10 22:41:10 +08:00
2025-03-08 23:05:02 +08:00
2025-03-10 18:09:27 +08:00
2025-03-10 18:09:27 +08:00
2025-03-08 23:05:02 +08:00
2025-03-08 23:05:02 +08:00
2025-03-08 23:05:02 +08:00
2025-03-10 22:41:10 +08:00

UZone

Usage

    1. usage present
    app := uzone.New()
    
    app.With(db, es, api)
    
    app.Run(ctx)
    
    1. simple example
    package main
    
    import (
        "github.com/loveuer/uzone"
        "github.com/loveuer/uzone/pkg/api"
        "github.com/loveuer/uzone/pkg/interfaces"
    )
    
    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 := uzone.New(uzone.Config{Debug: true})
    
        app.With(uzone.InitDB("sqlite://data.db", &Record{}))
        app.With(uzone.InitApi(api.New()))
    
        app.With(uzone.InitFn(func(u interfaces.Uzone) {
            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()
    }
    

Config

The program will load configuration files in the following order:

  • etc/config.yaml
  • etc/config.yml
  • config.json

Environment variables will take precedence and override any matching configurations found in the files above.

Description
No description provided
Readme 166 KiB
Languages
Go 100%