58 lines
1.5 KiB
Markdown
58 lines
1.5 KiB
Markdown
# UZone
|
|
|
|
### Usage
|
|
|
|
- 1. usage present
|
|
```go
|
|
app := uzone.New()
|
|
|
|
app.With(db, es, api)
|
|
|
|
app.Run(ctx)
|
|
```
|
|
|
|
- 2. simple example
|
|
```go
|
|
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. |