github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/pkg/depends/kit/httptransport/z_route_meta_test.go (about) 1 package httptransport_test 2 3 import ( 4 "fmt" 5 "os" 6 "sort" 7 8 "github.com/fatih/color" 9 10 "github.com/machinefi/w3bstream/pkg/depends/base/consts" 11 . "github.com/machinefi/w3bstream/pkg/depends/kit/httptransport" 12 "github.com/machinefi/w3bstream/pkg/depends/testutil/httptransporttestutil/server/cmd/app/routes" 13 ) 14 15 func ExampleGroup() { 16 g := Group("/test") 17 fmt.Println(g.Path()) 18 // Output: 19 // /test 20 } 21 22 func ExampleHttpRouteMeta() { 23 os.Setenv(consts.EnvProjectName, "service-example") 24 os.Setenv(consts.EnvProjectVersion, "1.0.0") 25 26 color.NoColor = true 27 28 routes := routes.RootRouter.Routes() 29 30 sort.Slice(routes, func(i, j int) bool { 31 return NewHttpRouteMeta(routes[i]).Key() < 32 NewHttpRouteMeta(routes[j]).Key() 33 }) 34 35 for i := range routes { 36 rm := NewHttpRouteMeta(routes[i]) 37 fmt.Println(rm.String()) 38 } 39 // Output: 40 // GET /demo openapi.OpenAPI 41 // GET /demo/binary/files routes.DownloadFile 42 // GET /demo/binary/images routes.ShowImage 43 // POS /demo/binary/protobuf routes.Protobuf 44 // POS /demo/cookie routes.Cookie 45 // POS /demo/forms/multipart routes.FormMultipartWithFile 46 // POS /demo/forms/multipart-with-files routes.FormMultipartWithFiles 47 // POS /demo/forms/urlencoded routes.FormURLEncoded 48 // GET /demo/proxy routes.Proxy 49 // GET /demo/redirect routes.Redirect 50 // POS /demo/redirect routes.RedirectWhenError 51 // POS /demo/restful routes.Create 52 // HEA /demo/restful routes.HealthCheck 53 // GET /demo/restful/{id} routes.DataProvider routes.GetByID 54 // DEL /demo/restful/{id} routes.DataProvider routes.RemoveByID 55 // PUT /demo/restful/{id} routes.DataProvider routes.UpdateByID 56 // GET /demo/v2/proxy routes.ProxyV2 57 }