github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/pkg/depends/kit/httptransport/openapi/openapi.go (about) 1 package openapi 2 3 import ( 4 "bytes" 5 "context" 6 "io/ioutil" 7 8 "github.com/machinefi/w3bstream/pkg/depends/kit/httptransport/httpx" 9 "github.com/machinefi/w3bstream/pkg/depends/kit/kit" 10 ) 11 12 var raw = bytes.NewBuffer(nil) 13 14 func init() { 15 data, err := ioutil.ReadFile("./openapi.json") 16 if err == nil { 17 raw.Write(data) 18 } else { 19 raw.Write([]byte("{}")) 20 } 21 } 22 23 var Router = kit.NewRouter(OpenAPI{}) 24 25 type OpenAPI struct { 26 httpx.MethodGet 27 } 28 29 func (s OpenAPI) Output(ctx context.Context) (interface{}, error) { 30 return httpx.WrapContentType(httpx.MIME_JSON)(bytes.NewBuffer(raw.Bytes())), nil 31 }