wip: refactory uapp to uzone
feat: config first
This commit is contained in:
35
example/simple_usage/main.go
Normal file
35
example/simple_usage/main.go
Normal file
@ -0,0 +1,35 @@
|
||||
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()
|
||||
}
|
Reference in New Issue
Block a user