Defaults
go
// register api defaults to facade
import (
"context"
"fmt"
"net/http"
"comby.io/examples/simple/api"
"comby.io/examples/simple/domain"
"github.com/danielgtaylor/huma/v2"
"github.com/danielgtaylor/huma/v2/adapters/humago"
"github.com/gradientzero/comby/v2"
"github.com/gradientzero/comby/v2/web"
combyApi "github.com/gradientzero/comby/v2/api"
combyDomain "github.com/gradientzero/comby/v2/domain"
)
func main() {
// create empty facade
fc, _ := comby.NewFacade()
// register comby domains
if err := combyDomain.RegisterDefaults(context.Background(), fc); err != nil {
panic(err)
}
// register my domains
// restore state
if err := fc.RestoreState(); err != nil {
panic(err)
}
// create new mux
mux := http.NewServeMux()
// add comby admin dashboard
mux.Handle("/admin/", web.AdminHandler())
// add custom router handleFunc
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`hello world`))
})
// create huma api
humaApi := humago.New(mux, huma.DefaultConfig("My API", "1.0.0"))
// add comby's default api
if err := combyApi.RegisterDefaults(fc, humaApi); err != nil {
panic(err)
}
// register my api endpoints
// run http server
fmt.Println(fc.PrintInfo())
http.ListenAndServe("127.0.0.1:8080", mux)
}