You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
900 B

2 years ago
package main
import (
12 months ago
"context"
2 years ago
"flag"
2 years ago
"fmt"
2 years ago
"git.diulo.com/mogfee/kit"
12 months ago
"git.diulo.com/mogfee/kit/middleware"
2 years ago
"git.diulo.com/mogfee/kit/transport/http"
2 years ago
)
func main() {
2 years ago
flag.Parse()
12 months ago
runApp("localhost:8998")
2 years ago
}
func runApp(host string) {
1 year ago
hs := http.NewServer(
2 years ago
http.Address(host),
12 months ago
http.Middleware(func(handler middleware.Handler) middleware.Handler {
return func(ctx context.Context, a any) (any, error) {
fmt.Println("middleare 1")
return handler(ctx, a)
}
}),
2 years ago
)
12 months ago
hs.Use("/api/v2/user/me", func(handler middleware.Handler) middleware.Handler {
return func(ctx context.Context, a any) (any, error) {
fmt.Println("use midd")
return handler(ctx, a)
}
})
r := hs.Route("")
r.GET("/api/v2/user/me", func(ctx http.Context) error {
fmt.Println("/api/v2/user/me")
return nil
})
1 year ago
app := kit.New(kit.Server(hs))
2 years ago
fmt.Println(app.Run())
fmt.Println(app.Stop())
}