storj/private/apigen/example/gen.go
Jeremy Wharton 1f0638719e private/apigen,cmd/apigentest: add tests for generated API code
This change implements a unit test for ensuring proper
processing of requests and responses by generated API code.
Additionally, this change requires API handlers to explicitly receive
Monkit scopes rather than assuming that `mon` will always exist in the
generated API code's namespace.

Change-Id: Iea56f139f9dad0050b7d09ea765189280c3466f2
2022-08-15 16:48:41 +00:00

42 lines
767 B
Go

// Copyright (C) 2022 Storj Labs, Inc.
// See LICENSE for copying information.
//go:generate go run gen.go
//go:build ignore
// +build ignore
package main
import (
"time"
"storj.io/common/uuid"
"storj.io/storj/private/apigen"
)
func main() {
a := &apigen.API{PackageName: "example"}
g := a.Group("TestAPI", "testapi")
g.Post("/{path}", &apigen.Endpoint{
MethodName: "GenTestAPI",
Response: struct {
ID uuid.UUID
Date time.Time
PathParam string
Body string
}{},
Request: struct{ Content string }{},
QueryParams: []apigen.Param{
apigen.NewParam("id", uuid.UUID{}),
apigen.NewParam("date", time.Time{}),
},
PathParams: []apigen.Param{
apigen.NewParam("path", ""),
},
})
a.MustWriteGo("api.gen.go")
}