diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 4ced829..258608f 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -6,21 +6,9 @@ updates: interval: daily reviewers: - ikawaha - - package-ecosystem: gomod - directory: /plugin/goa - schedule: - interval: daily - reviewers: - - ikawaha - package-ecosystem: github-actions directory: / schedule: interval: daily reviewers: - ikawaha - - package-ecosystem: github-actions - directory: /plugin/goa - schedule: - interval: daily - reviewers: - - ikawaha diff --git a/plugin/goa/README.md b/plugin/goa/README.md deleted file mode 100644 index 170fe5e..0000000 --- a/plugin/goa/README.md +++ /dev/null @@ -1,46 +0,0 @@ -httpcheck Goa plugin -=== - -This plugin provides a mounter for the [Goa](http://github.com/goadesign/goa) HTTP endpoints, enabling seamless integration with [httpcheck](https://github.com/ikawaha/httpcheck). The mounter satisfies the http.Handler interface, allowing it to be directly set and utilized within httpcheck. - -## Usage Example - -The [following example](https://github.com/ikawaha/httpcheck/blob/5e434b64049b13f5558e83d26abdeaa28b281cd7/plugin/goa/_test/calc_test.go#L18-L35) demonstrates how to use the goa plugin to test a Goa HTTP endpoint. In this example, we're testing an endpoint that multiplies two numbers. - -```go -package calc - -import ( - "io" - "net/http" - "strconv" - "strings" - "testing" - - "github.com/ikawaha/httpcheck" - "github.com/ikawaha/httpcheck/plugin/goa" - gen "github.com/ikawaha/httpcheck/plugin/goa/calc/gen/calc" - "github.com/ikawaha/httpcheck/plugin/goa/calc/gen/http/calc/server" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" -) - -func TestMounter(t *testing.T) { - m := goa.NewMounter() - m.Mount(goa.EndpointModular{ - Builder: server.NewMultiplyHandler, - Mounter: server.MountMultiplyHandler, - Endpoint: gen.NewMultiplyEndpoint(NewCalc()), - }) - httpcheck.New(m).Test(t, "GET", "/multiply/3/5"). - Check(). - MustHasStatus(http.StatusOK). - Cb(func(r *http.Response) { - b, err := io.ReadAll(r.Body) - require.NoError(t, err) - i, err := strconv.Atoi(strings.TrimSpace(string(b))) - assert.NoError(t, err, string(b)) - assert.Equal(t, 3*5, i) - }) -} -``` \ No newline at end of file diff --git a/plugin/goa/_test/calc.go b/plugin/goa/_test/calc.go deleted file mode 100644 index 5ab07ee..0000000 --- a/plugin/goa/_test/calc.go +++ /dev/null @@ -1,21 +0,0 @@ -package calc - -import ( - "context" - - calcsvc "github.com/ikawaha/httpcheck/plugin/goa/calc/gen/calc" -) - -// calc service example implementation. -// The example methods log the requests and return zero values. -type calcSvc struct{} - -// NewCalc returns the calc service implementation. -func NewCalc() calcsvc.Service { - return &calcSvc{} -} - -// Multiply implements multiply. -func (s *calcSvc) Multiply(_ context.Context, p *calcsvc.MultiplyPayload) (int, error) { - return p.A * p.B, nil -} diff --git a/plugin/goa/_test/calc_test.go b/plugin/goa/_test/calc_test.go deleted file mode 100644 index 34d9336..0000000 --- a/plugin/goa/_test/calc_test.go +++ /dev/null @@ -1,35 +0,0 @@ -package calc - -import ( - "io" - "net/http" - "strconv" - "strings" - "testing" - - "github.com/ikawaha/httpcheck" - "github.com/ikawaha/httpcheck/plugin/goa" - gen "github.com/ikawaha/httpcheck/plugin/goa/calc/gen/calc" - "github.com/ikawaha/httpcheck/plugin/goa/calc/gen/http/calc/server" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" -) - -func TestMounter(t *testing.T) { - m := goa.NewMounter() - m.Mount(goa.EndpointModular{ - Builder: server.NewMultiplyHandler, - Mounter: server.MountMultiplyHandler, - Endpoint: gen.NewMultiplyEndpoint(NewCalc()), - }) - httpcheck.New(m).Test(t, "GET", "/multiply/3/5"). - Check(). - MustHasStatus(http.StatusOK). - Cb(func(r *http.Response) { - b, err := io.ReadAll(r.Body) - require.NoError(t, err) - i, err := strconv.Atoi(strings.TrimSpace(string(b))) - assert.NoError(t, err, string(b)) - assert.Equal(t, 3*5, i) - }) -} diff --git a/plugin/goa/_test/design/design.go b/plugin/goa/_test/design/design.go deleted file mode 100644 index 08097a5..0000000 --- a/plugin/goa/_test/design/design.go +++ /dev/null @@ -1,39 +0,0 @@ -package design - -import ( - . "goa.design/goa/v3/dsl" -) - -var _ = Service("calc", func() { - Description("The calc service performs operations on numbers") - - // Method describes a service method (endpoint) - Method("multiply", func() { - // Payload describes the method payload. - // Here the payload is an object that consists of two fields. - Payload(func() { - // Attribute describes an object field - Attribute("a", Int, "Left operand") - Attribute("b", Int, "Right operand") - Required("a", "b") - }) - - // Result describes the method result. - // Here the result is a simple integer value. - Result(Int) - - // HTTP describes the HTTP transport mapping. - HTTP(func() { - // Requests to the service consist of HTTP GET requests. - // The payload fields are encoded as path parameters. - GET("/multiply/{a}/{b}") - // Responses use a "200 OK" HTTP status. - // The result is encoded in the response body. - Response(StatusOK) - }) - }) - - // Serve the file gen/http/openapi3.json for requests sent to - // /openapi.json. - Files("/openapi.json", "openapi3.json") -}) diff --git a/plugin/goa/_test/gen/calc/client.go b/plugin/goa/_test/gen/calc/client.go deleted file mode 100644 index f6cf845..0000000 --- a/plugin/goa/_test/gen/calc/client.go +++ /dev/null @@ -1,36 +0,0 @@ -// Code generated by goa v3.13.2, DO NOT EDIT. -// -// calc client -// -// Command: -// $ goa gen github.com/ikawaha/httpcheck/plugin/goa/calc/design - -package calc - -import ( - "context" - - goa "goa.design/goa/v3/pkg" -) - -// Client is the "calc" service client. -type Client struct { - MultiplyEndpoint goa.Endpoint -} - -// NewClient initializes a "calc" service client given the endpoints. -func NewClient(multiply goa.Endpoint) *Client { - return &Client{ - MultiplyEndpoint: multiply, - } -} - -// Multiply calls the "multiply" endpoint of the "calc" service. -func (c *Client) Multiply(ctx context.Context, p *MultiplyPayload) (res int, err error) { - var ires any - ires, err = c.MultiplyEndpoint(ctx, p) - if err != nil { - return - } - return ires.(int), nil -} diff --git a/plugin/goa/_test/gen/calc/endpoints.go b/plugin/goa/_test/gen/calc/endpoints.go deleted file mode 100644 index 1da6b34..0000000 --- a/plugin/goa/_test/gen/calc/endpoints.go +++ /dev/null @@ -1,40 +0,0 @@ -// Code generated by goa v3.13.2, DO NOT EDIT. -// -// calc endpoints -// -// Command: -// $ goa gen github.com/ikawaha/httpcheck/plugin/goa/calc/design - -package calc - -import ( - "context" - - goa "goa.design/goa/v3/pkg" -) - -// Endpoints wraps the "calc" service endpoints. -type Endpoints struct { - Multiply goa.Endpoint -} - -// NewEndpoints wraps the methods of the "calc" service with endpoints. -func NewEndpoints(s Service) *Endpoints { - return &Endpoints{ - Multiply: NewMultiplyEndpoint(s), - } -} - -// Use applies the given middleware to all the "calc" service endpoints. -func (e *Endpoints) Use(m func(goa.Endpoint) goa.Endpoint) { - e.Multiply = m(e.Multiply) -} - -// NewMultiplyEndpoint returns an endpoint function that calls the method -// "multiply" of service "calc". -func NewMultiplyEndpoint(s Service) goa.Endpoint { - return func(ctx context.Context, req any) (any, error) { - p := req.(*MultiplyPayload) - return s.Multiply(ctx, p) - } -} diff --git a/plugin/goa/_test/gen/calc/service.go b/plugin/goa/_test/gen/calc/service.go deleted file mode 100644 index 6daed37..0000000 --- a/plugin/goa/_test/gen/calc/service.go +++ /dev/null @@ -1,36 +0,0 @@ -// Code generated by goa v3.13.2, DO NOT EDIT. -// -// calc service -// -// Command: -// $ goa gen github.com/ikawaha/httpcheck/plugin/goa/calc/design - -package calc - -import ( - "context" -) - -// The calc service performs operations on numbers -type Service interface { - // Multiply implements multiply. - Multiply(context.Context, *MultiplyPayload) (res int, err error) -} - -// ServiceName is the name of the service as defined in the design. This is the -// same value that is set in the endpoint request contexts under the ServiceKey -// key. -const ServiceName = "calc" - -// MethodNames lists the service method names as defined in the design. These -// are the same values that are set in the endpoint request contexts under the -// MethodKey key. -var MethodNames = [1]string{"multiply"} - -// MultiplyPayload is the payload type of the calc service multiply method. -type MultiplyPayload struct { - // Left operand - A int - // Right operand - B int -} diff --git a/plugin/goa/_test/gen/http/calc/client/cli.go b/plugin/goa/_test/gen/http/calc/client/cli.go deleted file mode 100644 index aa2f81e..0000000 --- a/plugin/goa/_test/gen/http/calc/client/cli.go +++ /dev/null @@ -1,44 +0,0 @@ -// Code generated by goa v3.13.2, DO NOT EDIT. -// -// calc HTTP client CLI support package -// -// Command: -// $ goa gen github.com/ikawaha/httpcheck/plugin/goa/calc/design - -package client - -import ( - "fmt" - "strconv" - - calc "github.com/ikawaha/httpcheck/plugin/goa/calc/gen/calc" -) - -// BuildMultiplyPayload builds the payload for the calc multiply endpoint from -// CLI flags. -func BuildMultiplyPayload(calcMultiplyA string, calcMultiplyB string) (*calc.MultiplyPayload, error) { - var err error - var a int - { - var v int64 - v, err = strconv.ParseInt(calcMultiplyA, 10, strconv.IntSize) - a = int(v) - if err != nil { - return nil, fmt.Errorf("invalid value for a, must be INT") - } - } - var b int - { - var v int64 - v, err = strconv.ParseInt(calcMultiplyB, 10, strconv.IntSize) - b = int(v) - if err != nil { - return nil, fmt.Errorf("invalid value for b, must be INT") - } - } - v := &calc.MultiplyPayload{} - v.A = a - v.B = b - - return v, nil -} diff --git a/plugin/goa/_test/gen/http/calc/client/client.go b/plugin/goa/_test/gen/http/calc/client/client.go deleted file mode 100644 index e2a4351..0000000 --- a/plugin/goa/_test/gen/http/calc/client/client.go +++ /dev/null @@ -1,70 +0,0 @@ -// Code generated by goa v3.13.2, DO NOT EDIT. -// -// calc client HTTP transport -// -// Command: -// $ goa gen github.com/ikawaha/httpcheck/plugin/goa/calc/design - -package client - -import ( - "context" - "net/http" - - goahttp "goa.design/goa/v3/http" - goa "goa.design/goa/v3/pkg" -) - -// Client lists the calc service endpoint HTTP clients. -type Client struct { - // Multiply Doer is the HTTP client used to make requests to the multiply - // endpoint. - MultiplyDoer goahttp.Doer - - // RestoreResponseBody controls whether the response bodies are reset after - // decoding so they can be read again. - RestoreResponseBody bool - - scheme string - host string - encoder func(*http.Request) goahttp.Encoder - decoder func(*http.Response) goahttp.Decoder -} - -// NewClient instantiates HTTP clients for all the calc service servers. -func NewClient( - scheme string, - host string, - doer goahttp.Doer, - enc func(*http.Request) goahttp.Encoder, - dec func(*http.Response) goahttp.Decoder, - restoreBody bool, -) *Client { - return &Client{ - MultiplyDoer: doer, - RestoreResponseBody: restoreBody, - scheme: scheme, - host: host, - decoder: dec, - encoder: enc, - } -} - -// Multiply returns an endpoint that makes HTTP requests to the calc service -// multiply server. -func (c *Client) Multiply() goa.Endpoint { - var ( - decodeResponse = DecodeMultiplyResponse(c.decoder, c.RestoreResponseBody) - ) - return func(ctx context.Context, v any) (any, error) { - req, err := c.BuildMultiplyRequest(ctx, v) - if err != nil { - return nil, err - } - resp, err := c.MultiplyDoer.Do(req) - if err != nil { - return nil, goahttp.ErrRequestError("calc", "multiply", err) - } - return decodeResponse(resp) - } -} diff --git a/plugin/goa/_test/gen/http/calc/client/encode_decode.go b/plugin/goa/_test/gen/http/calc/client/encode_decode.go deleted file mode 100644 index 3e2d352..0000000 --- a/plugin/goa/_test/gen/http/calc/client/encode_decode.go +++ /dev/null @@ -1,81 +0,0 @@ -// Code generated by goa v3.13.2, DO NOT EDIT. -// -// calc HTTP client encoders and decoders -// -// Command: -// $ goa gen github.com/ikawaha/httpcheck/plugin/goa/calc/design - -package client - -import ( - "bytes" - "context" - "io" - "net/http" - "net/url" - - calc "github.com/ikawaha/httpcheck/plugin/goa/calc/gen/calc" - goahttp "goa.design/goa/v3/http" -) - -// BuildMultiplyRequest instantiates a HTTP request object with method and path -// set to call the "calc" service "multiply" endpoint -func (c *Client) BuildMultiplyRequest(ctx context.Context, v any) (*http.Request, error) { - var ( - a int - b int - ) - { - p, ok := v.(*calc.MultiplyPayload) - if !ok { - return nil, goahttp.ErrInvalidType("calc", "multiply", "*calc.MultiplyPayload", v) - } - a = p.A - b = p.B - } - u := &url.URL{Scheme: c.scheme, Host: c.host, Path: MultiplyCalcPath(a, b)} - req, err := http.NewRequest("GET", u.String(), nil) - if err != nil { - return nil, goahttp.ErrInvalidURL("calc", "multiply", u.String(), err) - } - if ctx != nil { - req = req.WithContext(ctx) - } - - return req, nil -} - -// DecodeMultiplyResponse returns a decoder for responses returned by the calc -// multiply endpoint. restoreBody controls whether the response body should be -// restored after having been read. -func DecodeMultiplyResponse(decoder func(*http.Response) goahttp.Decoder, restoreBody bool) func(*http.Response) (any, error) { - return func(resp *http.Response) (any, error) { - if restoreBody { - b, err := io.ReadAll(resp.Body) - if err != nil { - return nil, err - } - resp.Body = io.NopCloser(bytes.NewBuffer(b)) - defer func() { - resp.Body = io.NopCloser(bytes.NewBuffer(b)) - }() - } else { - defer resp.Body.Close() - } - switch resp.StatusCode { - case http.StatusOK: - var ( - body int - err error - ) - err = decoder(resp).Decode(&body) - if err != nil { - return nil, goahttp.ErrDecodingError("calc", "multiply", err) - } - return body, nil - default: - body, _ := io.ReadAll(resp.Body) - return nil, goahttp.ErrInvalidResponse("calc", "multiply", resp.StatusCode, string(body)) - } - } -} diff --git a/plugin/goa/_test/gen/http/calc/client/paths.go b/plugin/goa/_test/gen/http/calc/client/paths.go deleted file mode 100644 index 3866235..0000000 --- a/plugin/goa/_test/gen/http/calc/client/paths.go +++ /dev/null @@ -1,17 +0,0 @@ -// Code generated by goa v3.13.2, DO NOT EDIT. -// -// HTTP request path constructors for the calc service. -// -// Command: -// $ goa gen github.com/ikawaha/httpcheck/plugin/goa/calc/design - -package client - -import ( - "fmt" -) - -// MultiplyCalcPath returns the URL path to the calc service multiply HTTP endpoint. -func MultiplyCalcPath(a int, b int) string { - return fmt.Sprintf("/multiply/%v/%v", a, b) -} diff --git a/plugin/goa/_test/gen/http/calc/client/types.go b/plugin/goa/_test/gen/http/calc/client/types.go deleted file mode 100644 index 993fdcf..0000000 --- a/plugin/goa/_test/gen/http/calc/client/types.go +++ /dev/null @@ -1,8 +0,0 @@ -// Code generated by goa v3.13.2, DO NOT EDIT. -// -// calc HTTP client types -// -// Command: -// $ goa gen github.com/ikawaha/httpcheck/plugin/goa/calc/design - -package client diff --git a/plugin/goa/_test/gen/http/calc/server/encode_decode.go b/plugin/goa/_test/gen/http/calc/server/encode_decode.go deleted file mode 100644 index 34febed..0000000 --- a/plugin/goa/_test/gen/http/calc/server/encode_decode.go +++ /dev/null @@ -1,65 +0,0 @@ -// Code generated by goa v3.13.2, DO NOT EDIT. -// -// calc HTTP server encoders and decoders -// -// Command: -// $ goa gen github.com/ikawaha/httpcheck/plugin/goa/calc/design - -package server - -import ( - "context" - "net/http" - "strconv" - - goahttp "goa.design/goa/v3/http" - goa "goa.design/goa/v3/pkg" -) - -// EncodeMultiplyResponse returns an encoder for responses returned by the calc -// multiply endpoint. -func EncodeMultiplyResponse(encoder func(context.Context, http.ResponseWriter) goahttp.Encoder) func(context.Context, http.ResponseWriter, any) error { - return func(ctx context.Context, w http.ResponseWriter, v any) error { - res, _ := v.(int) - enc := encoder(ctx, w) - body := res - w.WriteHeader(http.StatusOK) - return enc.Encode(body) - } -} - -// DecodeMultiplyRequest returns a decoder for requests sent to the calc -// multiply endpoint. -func DecodeMultiplyRequest(mux goahttp.Muxer, decoder func(*http.Request) goahttp.Decoder) func(*http.Request) (any, error) { - return func(r *http.Request) (any, error) { - var ( - a int - b int - err error - - params = mux.Vars(r) - ) - { - aRaw := params["a"] - v, err2 := strconv.ParseInt(aRaw, 10, strconv.IntSize) - if err2 != nil { - err = goa.MergeErrors(err, goa.InvalidFieldTypeError("a", aRaw, "integer")) - } - a = int(v) - } - { - bRaw := params["b"] - v, err2 := strconv.ParseInt(bRaw, 10, strconv.IntSize) - if err2 != nil { - err = goa.MergeErrors(err, goa.InvalidFieldTypeError("b", bRaw, "integer")) - } - b = int(v) - } - if err != nil { - return nil, err - } - payload := NewMultiplyPayload(a, b) - - return payload, nil - } -} diff --git a/plugin/goa/_test/gen/http/calc/server/paths.go b/plugin/goa/_test/gen/http/calc/server/paths.go deleted file mode 100644 index 6093e77..0000000 --- a/plugin/goa/_test/gen/http/calc/server/paths.go +++ /dev/null @@ -1,17 +0,0 @@ -// Code generated by goa v3.13.2, DO NOT EDIT. -// -// HTTP request path constructors for the calc service. -// -// Command: -// $ goa gen github.com/ikawaha/httpcheck/plugin/goa/calc/design - -package server - -import ( - "fmt" -) - -// MultiplyCalcPath returns the URL path to the calc service multiply HTTP endpoint. -func MultiplyCalcPath(a int, b int) string { - return fmt.Sprintf("/multiply/%v/%v", a, b) -} diff --git a/plugin/goa/_test/gen/http/calc/server/server.go b/plugin/goa/_test/gen/http/calc/server/server.go deleted file mode 100644 index e7b5313..0000000 --- a/plugin/goa/_test/gen/http/calc/server/server.go +++ /dev/null @@ -1,142 +0,0 @@ -// Code generated by goa v3.13.2, DO NOT EDIT. -// -// calc HTTP server -// -// Command: -// $ goa gen github.com/ikawaha/httpcheck/plugin/goa/calc/design - -package server - -import ( - "context" - "net/http" - - calc "github.com/ikawaha/httpcheck/plugin/goa/calc/gen/calc" - goahttp "goa.design/goa/v3/http" - goa "goa.design/goa/v3/pkg" -) - -// Server lists the calc service endpoint HTTP handlers. -type Server struct { - Mounts []*MountPoint - Multiply http.Handler - Openapi3JSON http.Handler -} - -// MountPoint holds information about the mounted endpoints. -type MountPoint struct { - // Method is the name of the service method served by the mounted HTTP handler. - Method string - // Verb is the HTTP method used to match requests to the mounted handler. - Verb string - // Pattern is the HTTP request path pattern used to match requests to the - // mounted handler. - Pattern string -} - -// New instantiates HTTP handlers for all the calc service endpoints using the -// provided encoder and decoder. The handlers are mounted on the given mux -// using the HTTP verb and path defined in the design. errhandler is called -// whenever a response fails to be encoded. formatter is used to format errors -// returned by the service methods prior to encoding. Both errhandler and -// formatter are optional and can be nil. -func New( - e *calc.Endpoints, - mux goahttp.Muxer, - decoder func(*http.Request) goahttp.Decoder, - encoder func(context.Context, http.ResponseWriter) goahttp.Encoder, - errhandler func(context.Context, http.ResponseWriter, error), - formatter func(ctx context.Context, err error) goahttp.Statuser, - fileSystemOpenapi3JSON http.FileSystem, -) *Server { - if fileSystemOpenapi3JSON == nil { - fileSystemOpenapi3JSON = http.Dir(".") - } - return &Server{ - Mounts: []*MountPoint{ - {"Multiply", "GET", "/multiply/{a}/{b}"}, - {"openapi3.json", "GET", "/openapi.json"}, - }, - Multiply: NewMultiplyHandler(e.Multiply, mux, decoder, encoder, errhandler, formatter), - Openapi3JSON: http.FileServer(fileSystemOpenapi3JSON), - } -} - -// Service returns the name of the service served. -func (s *Server) Service() string { return "calc" } - -// Use wraps the server handlers with the given middleware. -func (s *Server) Use(m func(http.Handler) http.Handler) { - s.Multiply = m(s.Multiply) -} - -// MethodNames returns the methods served. -func (s *Server) MethodNames() []string { return calc.MethodNames[:] } - -// Mount configures the mux to serve the calc endpoints. -func Mount(mux goahttp.Muxer, h *Server) { - MountMultiplyHandler(mux, h.Multiply) - MountOpenapi3JSON(mux, goahttp.Replace("", "/openapi3.json", h.Openapi3JSON)) -} - -// Mount configures the mux to serve the calc endpoints. -func (s *Server) Mount(mux goahttp.Muxer) { - Mount(mux, s) -} - -// MountMultiplyHandler configures the mux to serve the "calc" service -// "multiply" endpoint. -func MountMultiplyHandler(mux goahttp.Muxer, h http.Handler) { - f, ok := h.(http.HandlerFunc) - if !ok { - f = func(w http.ResponseWriter, r *http.Request) { - h.ServeHTTP(w, r) - } - } - mux.Handle("GET", "/multiply/{a}/{b}", f) -} - -// NewMultiplyHandler creates a HTTP handler which loads the HTTP request and -// calls the "calc" service "multiply" endpoint. -func NewMultiplyHandler( - endpoint goa.Endpoint, - mux goahttp.Muxer, - decoder func(*http.Request) goahttp.Decoder, - encoder func(context.Context, http.ResponseWriter) goahttp.Encoder, - errhandler func(context.Context, http.ResponseWriter, error), - formatter func(ctx context.Context, err error) goahttp.Statuser, -) http.Handler { - var ( - decodeRequest = DecodeMultiplyRequest(mux, decoder) - encodeResponse = EncodeMultiplyResponse(encoder) - encodeError = goahttp.ErrorEncoder(encoder, formatter) - ) - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - ctx := context.WithValue(r.Context(), goahttp.AcceptTypeKey, r.Header.Get("Accept")) - ctx = context.WithValue(ctx, goa.MethodKey, "multiply") - ctx = context.WithValue(ctx, goa.ServiceKey, "calc") - payload, err := decodeRequest(r) - if err != nil { - if err := encodeError(ctx, w, err); err != nil { - errhandler(ctx, w, err) - } - return - } - res, err := endpoint(ctx, payload) - if err != nil { - if err := encodeError(ctx, w, err); err != nil { - errhandler(ctx, w, err) - } - return - } - if err := encodeResponse(ctx, w, res); err != nil { - errhandler(ctx, w, err) - } - }) -} - -// MountOpenapi3JSON configures the mux to serve GET request made to -// "/openapi.json". -func MountOpenapi3JSON(mux goahttp.Muxer, h http.Handler) { - mux.Handle("GET", "/openapi.json", h.ServeHTTP) -} diff --git a/plugin/goa/_test/gen/http/calc/server/types.go b/plugin/goa/_test/gen/http/calc/server/types.go deleted file mode 100644 index 117cbc1..0000000 --- a/plugin/goa/_test/gen/http/calc/server/types.go +++ /dev/null @@ -1,21 +0,0 @@ -// Code generated by goa v3.13.2, DO NOT EDIT. -// -// calc HTTP server types -// -// Command: -// $ goa gen github.com/ikawaha/httpcheck/plugin/goa/calc/design - -package server - -import ( - calc "github.com/ikawaha/httpcheck/plugin/goa/calc/gen/calc" -) - -// NewMultiplyPayload builds a calc service multiply endpoint payload. -func NewMultiplyPayload(a int, b int) *calc.MultiplyPayload { - v := &calc.MultiplyPayload{} - v.A = a - v.B = b - - return v -} diff --git a/plugin/goa/_test/gen/http/cli/calc/cli.go b/plugin/goa/_test/gen/http/cli/calc/cli.go deleted file mode 100644 index 4cf130a..0000000 --- a/plugin/goa/_test/gen/http/cli/calc/cli.go +++ /dev/null @@ -1,152 +0,0 @@ -// Code generated by goa v3.13.2, DO NOT EDIT. -// -// calc HTTP client CLI support package -// -// Command: -// $ goa gen github.com/ikawaha/httpcheck/plugin/goa/calc/design - -package cli - -import ( - "flag" - "fmt" - "net/http" - "os" - - calcc "github.com/ikawaha/httpcheck/plugin/goa/calc/gen/http/calc/client" - goahttp "goa.design/goa/v3/http" - goa "goa.design/goa/v3/pkg" -) - -// UsageCommands returns the set of commands and sub-commands using the format -// -// command (subcommand1|subcommand2|...) -func UsageCommands() string { - return `calc multiply -` -} - -// UsageExamples produces an example of a valid invocation of the CLI tool. -func UsageExamples() string { - return os.Args[0] + ` calc multiply --a 5952269320165453119 --b 1828520165265779840` + "\n" + - "" -} - -// ParseEndpoint returns the endpoint and payload as specified on the command -// line. -func ParseEndpoint( - scheme, host string, - doer goahttp.Doer, - enc func(*http.Request) goahttp.Encoder, - dec func(*http.Response) goahttp.Decoder, - restore bool, -) (goa.Endpoint, any, error) { - var ( - calcFlags = flag.NewFlagSet("calc", flag.ContinueOnError) - - calcMultiplyFlags = flag.NewFlagSet("multiply", flag.ExitOnError) - calcMultiplyAFlag = calcMultiplyFlags.String("a", "REQUIRED", "Left operand") - calcMultiplyBFlag = calcMultiplyFlags.String("b", "REQUIRED", "Right operand") - ) - calcFlags.Usage = calcUsage - calcMultiplyFlags.Usage = calcMultiplyUsage - - if err := flag.CommandLine.Parse(os.Args[1:]); err != nil { - return nil, nil, err - } - - if flag.NArg() < 2 { // two non flag args are required: SERVICE and ENDPOINT (aka COMMAND) - return nil, nil, fmt.Errorf("not enough arguments") - } - - var ( - svcn string - svcf *flag.FlagSet - ) - { - svcn = flag.Arg(0) - switch svcn { - case "calc": - svcf = calcFlags - default: - return nil, nil, fmt.Errorf("unknown service %q", svcn) - } - } - if err := svcf.Parse(flag.Args()[1:]); err != nil { - return nil, nil, err - } - - var ( - epn string - epf *flag.FlagSet - ) - { - epn = svcf.Arg(0) - switch svcn { - case "calc": - switch epn { - case "multiply": - epf = calcMultiplyFlags - - } - - } - } - if epf == nil { - return nil, nil, fmt.Errorf("unknown %q endpoint %q", svcn, epn) - } - - // Parse endpoint flags if any - if svcf.NArg() > 1 { - if err := epf.Parse(svcf.Args()[1:]); err != nil { - return nil, nil, err - } - } - - var ( - data any - endpoint goa.Endpoint - err error - ) - { - switch svcn { - case "calc": - c := calcc.NewClient(scheme, host, doer, enc, dec, restore) - switch epn { - case "multiply": - endpoint = c.Multiply() - data, err = calcc.BuildMultiplyPayload(*calcMultiplyAFlag, *calcMultiplyBFlag) - } - } - } - if err != nil { - return nil, nil, err - } - - return endpoint, data, nil -} - -// calcUsage displays the usage of the calc command and its subcommands. -func calcUsage() { - fmt.Fprintf(os.Stderr, `The calc service performs operations on numbers -Usage: - %[1]s [globalflags] calc COMMAND [flags] - -COMMAND: - multiply: Multiply implements multiply. - -Additional help: - %[1]s calc COMMAND --help -`, os.Args[0]) -} -func calcMultiplyUsage() { - fmt.Fprintf(os.Stderr, `%[1]s [flags] calc multiply -a INT -b INT - -Multiply implements multiply. - -a INT: Left operand - -b INT: Right operand - -Example: - %[1]s calc multiply --a 5952269320165453119 --b 1828520165265779840 -`, os.Args[0]) -} diff --git a/plugin/goa/_test/gen/http/openapi.json b/plugin/goa/_test/gen/http/openapi.json deleted file mode 100644 index 465755e..0000000 --- a/plugin/goa/_test/gen/http/openapi.json +++ /dev/null @@ -1 +0,0 @@ -{"swagger":"2.0","info":{"title":"","version":""},"host":"localhost:80","consumes":["application/json","application/xml","application/gob"],"produces":["application/json","application/xml","application/gob"],"paths":{"/multiply/{a}/{b}":{"get":{"tags":["calc"],"summary":"multiply calc","operationId":"calc#multiply","parameters":[{"name":"a","in":"path","description":"Left operand","required":true,"type":"integer"},{"name":"b","in":"path","description":"Right operand","required":true,"type":"integer"}],"responses":{"200":{"description":"OK response.","schema":{"type":"integer","format":"int64"}}},"schemes":["http"]}},"/openapi.json":{"get":{"tags":["calc"],"summary":"Download openapi3.json","operationId":"calc#/openapi.json","responses":{"200":{"description":"File downloaded","schema":{"type":"file"}}},"schemes":["http"]}}}} \ No newline at end of file diff --git a/plugin/goa/_test/gen/http/openapi.yaml b/plugin/goa/_test/gen/http/openapi.yaml deleted file mode 100644 index c56eda3..0000000 --- a/plugin/goa/_test/gen/http/openapi.yaml +++ /dev/null @@ -1,52 +0,0 @@ -swagger: "2.0" -info: - title: "" - version: "" -host: localhost:80 -consumes: - - application/json - - application/xml - - application/gob -produces: - - application/json - - application/xml - - application/gob -paths: - /multiply/{a}/{b}: - get: - tags: - - calc - summary: multiply calc - operationId: calc#multiply - parameters: - - name: a - in: path - description: Left operand - required: true - type: integer - - name: b - in: path - description: Right operand - required: true - type: integer - responses: - "200": - description: OK response. - schema: - type: integer - format: int64 - schemes: - - http - /openapi.json: - get: - tags: - - calc - summary: Download openapi3.json - operationId: calc#/openapi.json - responses: - "200": - description: File downloaded - schema: - type: file - schemes: - - http diff --git a/plugin/goa/_test/gen/http/openapi3.json b/plugin/goa/_test/gen/http/openapi3.json deleted file mode 100644 index 103be1e..0000000 --- a/plugin/goa/_test/gen/http/openapi3.json +++ /dev/null @@ -1 +0,0 @@ -{"openapi":"3.0.3","info":{"title":"Goa API","version":"1.0"},"servers":[{"url":"http://localhost:80","description":"Default server for calc"}],"paths":{"/multiply/{a}/{b}":{"get":{"tags":["calc"],"summary":"multiply calc","operationId":"calc#multiply","parameters":[{"name":"a","in":"path","description":"Left operand","required":true,"schema":{"type":"integer","description":"Left operand","example":360622074634248926,"format":"int64"},"example":8133055152903002499},{"name":"b","in":"path","description":"Right operand","required":true,"schema":{"type":"integer","description":"Right operand","example":3219793201326175278,"format":"int64"},"example":8803302123552712831}],"responses":{"200":{"description":"OK response.","content":{"application/json":{"schema":{"type":"integer","example":8399553735696626949,"format":"int64"},"example":5401762099778430809}}}}}},"/openapi.json":{"get":{"tags":["calc"],"summary":"Download openapi3.json","operationId":"calc#/openapi.json","responses":{"200":{"description":"File downloaded"}}}}},"components":{},"tags":[{"name":"calc","description":"The calc service performs operations on numbers"}]} \ No newline at end of file diff --git a/plugin/goa/_test/gen/http/openapi3.yaml b/plugin/goa/_test/gen/http/openapi3.yaml deleted file mode 100644 index 6a8efbf..0000000 --- a/plugin/goa/_test/gen/http/openapi3.yaml +++ /dev/null @@ -1,58 +0,0 @@ -openapi: 3.0.3 -info: - title: Goa API - version: "1.0" -servers: - - url: http://localhost:80 - description: Default server for calc -paths: - /multiply/{a}/{b}: - get: - tags: - - calc - summary: multiply calc - operationId: calc#multiply - parameters: - - name: a - in: path - description: Left operand - required: true - schema: - type: integer - description: Left operand - example: 360622074634248926 - format: int64 - example: 8133055152903002499 - - name: b - in: path - description: Right operand - required: true - schema: - type: integer - description: Right operand - example: 3219793201326175278 - format: int64 - example: 8803302123552712831 - responses: - "200": - description: OK response. - content: - application/json: - schema: - type: integer - example: 8399553735696626949 - format: int64 - example: 5401762099778430809 - /openapi.json: - get: - tags: - - calc - summary: Download openapi3.json - operationId: calc#/openapi.json - responses: - "200": - description: File downloaded -components: {} -tags: - - name: calc - description: The calc service performs operations on numbers diff --git a/plugin/goa/_test/go.mod b/plugin/goa/_test/go.mod deleted file mode 100644 index 1ab97a9..0000000 --- a/plugin/goa/_test/go.mod +++ /dev/null @@ -1,29 +0,0 @@ -module github.com/ikawaha/httpcheck/plugin/goa/calc - -go 1.21.3 - -replace github.com/ikawaha/httpcheck/plugin/goa => ../ - -require ( - github.com/ikawaha/httpcheck v1.10.1 - github.com/ikawaha/httpcheck/plugin/goa v0.0.0-00010101000000-000000000000 - github.com/stretchr/testify v1.8.4 - goa.design/goa/v3 v3.14.6 -) - -require ( - github.com/AnatolyRugalev/goregen v0.1.0 // indirect - github.com/davecgh/go-spew v1.1.1 // indirect - github.com/dimfeld/httppath v0.0.0-20170720192232-ee938bf73598 // indirect - github.com/go-chi/chi/v5 v5.0.11 // indirect - github.com/google/uuid v1.6.0 // indirect - github.com/gorilla/websocket v1.5.1 // indirect - github.com/manveru/faker v0.0.0-20171103152722-9fbc68a78c4d // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/sergi/go-diff v1.3.1 // indirect - golang.org/x/mod v0.14.0 // indirect - golang.org/x/sys v0.16.0 // indirect - golang.org/x/text v0.14.0 // indirect - golang.org/x/tools v0.17.0 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect -) diff --git a/plugin/goa/_test/go.sum b/plugin/goa/_test/go.sum deleted file mode 100644 index d4b35d1..0000000 --- a/plugin/goa/_test/go.sum +++ /dev/null @@ -1,67 +0,0 @@ -github.com/AnatolyRugalev/goregen v0.1.0 h1:xrdXkLaskMnbxW0x4FWNj2yoednv0X2bcTBWpuJGYfE= -github.com/AnatolyRugalev/goregen v0.1.0/go.mod h1:sVlY1tjcirqLBRZnCcIq1+7/Lwmqz5g7IK8AStjOVzI= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dimfeld/httppath v0.0.0-20170720192232-ee938bf73598 h1:MGKhKyiYrvMDZsmLR/+RGffQSXwEkXgfLSA08qDn9AI= -github.com/dimfeld/httppath v0.0.0-20170720192232-ee938bf73598/go.mod h1:0FpDmbrt36utu8jEmeU05dPC9AB5tsLYVVi+ZHfyuwI= -github.com/go-chi/chi/v5 v5.0.10 h1:rLz5avzKpjqxrYwXNfmjkrYYXOyLJd37pz53UFHC6vk= -github.com/go-chi/chi/v5 v5.0.10/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= -github.com/go-chi/chi/v5 v5.0.11/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= -github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= -github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= -github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= -github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= -github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY= -github.com/ikawaha/httpcheck v1.9.0 h1:9QhAOM3Bobh36dFoxmGoNz6ec/ICPLWgnM/3am+0B4A= -github.com/ikawaha/httpcheck v1.9.0/go.mod h1:K5tBCuIIufz1MXGqqfXnFEu5FZy2y1bhR/7jDHIvoQ0= -github.com/ikawaha/httpcheck v1.10.1 h1:1UhgQCaxn6Dhujw0bfF2SPCw5Ue6LLwJufmfhW5GOj4= -github.com/ikawaha/httpcheck v1.10.1/go.mod h1:mICgpunMfsAjsSX6AocPp+ctplen5/lmh8yXJ+fbeac= -github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/manveru/faker v0.0.0-20171103152722-9fbc68a78c4d h1:Zj+PHjnhRYWBK6RqCDBcAhLXoi3TzC27Zad/Vn+gnVQ= -github.com/manveru/faker v0.0.0-20171103152722-9fbc68a78c4d/go.mod h1:WZy8Q5coAB1zhY9AOBJP0O6J4BuDfbupUDavKY+I3+s= -github.com/manveru/gobdd v0.0.0-20131210092515-f1a17fdd710b h1:3E44bLeN8uKYdfQqVQycPnaVviZdBLbizFhU49mtbe4= -github.com/manveru/gobdd v0.0.0-20131210092515-f1a17fdd710b/go.mod h1:Bj8LjjP0ReT1eKt5QlKjwgi5AFm5mI6O1A2G4ChI0Ag= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8= -github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -goa.design/goa/v3 v3.13.2 h1:RclNIpo7891ZqGRVO4fpBjT7Fs7LjBNm78i8J41KHrI= -goa.design/goa/v3 v3.13.2/go.mod h1:VvZsuC8CSIUQOHVqk6Ep3MFSFz21OjOv87UPqCHiB94= -goa.design/goa/v3 v3.14.1/go.mod h1:MhHWTSB7X6qVuNvjDTNtr/YQyYi9x1I4zfPtXnCdHtQ= -goa.design/goa/v3 v3.14.6 h1:mbu6n9be7puIqhn95zZaccn+k3QVqiR5teLvIrznt5c= -goa.design/goa/v3 v3.14.6/go.mod h1:wcdZ2jy4oC2R93R3kBWKqyDapkVLQbILkOLXcqWMXHY= -golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc= -golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= -golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= -golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= -golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= -golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= -golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= -golang.org/x/tools v0.13.0 h1:Iey4qkscZuv0VvIt8E0neZjtPVQFSc870HQ448QgEmQ= -golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58= -golang.org/x/tools v0.16.0/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0= -golang.org/x/tools v0.17.0/go.mod h1:xsh6VxdV005rRVaS6SSAf9oiAqljS7UZUacMZ8Bnsps= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= -gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/plugin/goa/go.mod b/plugin/goa/go.mod deleted file mode 100644 index 5a5a638..0000000 --- a/plugin/goa/go.mod +++ /dev/null @@ -1,21 +0,0 @@ -module github.com/ikawaha/httpcheck/plugin/goa - -go 1.21.3 - -require ( - github.com/ikawaha/httpcheck v1.10.1 - goa.design/goa/v3 v3.14.6 -) - -require ( - github.com/davecgh/go-spew v1.1.1 // indirect - github.com/go-chi/chi/v5 v5.0.11 // indirect - github.com/google/uuid v1.6.0 // indirect - github.com/gorilla/websocket v1.5.1 // indirect - github.com/kr/pretty v0.1.0 // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/stretchr/testify v1.8.4 // indirect - golang.org/x/net v0.20.0 // indirect - gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect -) diff --git a/plugin/goa/go.sum b/plugin/goa/go.sum deleted file mode 100644 index 42cfb9b..0000000 --- a/plugin/goa/go.sum +++ /dev/null @@ -1,41 +0,0 @@ -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/go-chi/chi/v5 v5.0.10 h1:rLz5avzKpjqxrYwXNfmjkrYYXOyLJd37pz53UFHC6vk= -github.com/go-chi/chi/v5 v5.0.10/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= -github.com/go-chi/chi/v5 v5.0.11 h1:BnpYbFZ3T3S1WMpD79r7R5ThWX40TaFB7L31Y8xqSwA= -github.com/go-chi/chi/v5 v5.0.11/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= -github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= -github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= -github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= -github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= -github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY= -github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY= -github.com/ikawaha/httpcheck v1.9.0 h1:9QhAOM3Bobh36dFoxmGoNz6ec/ICPLWgnM/3am+0B4A= -github.com/ikawaha/httpcheck v1.9.0/go.mod h1:K5tBCuIIufz1MXGqqfXnFEu5FZy2y1bhR/7jDHIvoQ0= -github.com/ikawaha/httpcheck v1.10.1 h1:1UhgQCaxn6Dhujw0bfF2SPCw5Ue6LLwJufmfhW5GOj4= -github.com/ikawaha/httpcheck v1.10.1/go.mod h1:mICgpunMfsAjsSX6AocPp+ctplen5/lmh8yXJ+fbeac= -github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -goa.design/goa/v3 v3.13.2 h1:RclNIpo7891ZqGRVO4fpBjT7Fs7LjBNm78i8J41KHrI= -goa.design/goa/v3 v3.13.2/go.mod h1:VvZsuC8CSIUQOHVqk6Ep3MFSFz21OjOv87UPqCHiB94= -goa.design/goa/v3 v3.14.1 h1:wNvKwCXeEJWmosd2MXaZHjJGm+wtEPCZf5jNXCx3oJo= -goa.design/goa/v3 v3.14.1/go.mod h1:MhHWTSB7X6qVuNvjDTNtr/YQyYi9x1I4zfPtXnCdHtQ= -goa.design/goa/v3 v3.14.6 h1:mbu6n9be7puIqhn95zZaccn+k3QVqiR5teLvIrznt5c= -goa.design/goa/v3 v3.14.6/go.mod h1:wcdZ2jy4oC2R93R3kBWKqyDapkVLQbILkOLXcqWMXHY= -golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo= -golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= -gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/plugin/goa/mounter.go b/plugin/goa/mounter.go deleted file mode 100644 index e870352..0000000 --- a/plugin/goa/mounter.go +++ /dev/null @@ -1,137 +0,0 @@ -package goa - -import ( - "context" - "log" - "net/http" - - "github.com/ikawaha/httpcheck" - - goahttp "goa.design/goa/v3/http" - goa "goa.design/goa/v3/pkg" -) - -var _ http.Handler = (*Mounter)(nil) - -type ( - // type aliases - decoder = func(*http.Request) goahttp.Decoder - encoder = func(context.Context, http.ResponseWriter) goahttp.Encoder - errorHandler = func(context.Context, http.ResponseWriter, error) - formatter = func(context.Context, error) goahttp.Statuser - middleware = func(http.Handler) http.Handler -) - -type ( - // HandlerBuilder represents the goa http handler builder. - HandlerBuilder func(goa.Endpoint, goahttp.Muxer, decoder, encoder, errorHandler, formatter) http.Handler - // HandlerMounter represents the goa http handler mounter. - HandlerMounter func(goahttp.Muxer, http.Handler) -) - -// Mounter represents Goa v3 handler mounter. -type Mounter struct { - Mux goahttp.Muxer - Middleware []middleware - Decoder decoder - Encoder encoder - ErrorHandler errorHandler - Formatter formatter - ClientOptions []httpcheck.Option -} - -// Option represents options for API checker. -type Option func(m *Mounter) - -// Muxer sets the goa http multiplexer. -func Muxer(mux goahttp.Muxer) Option { - return func(m *Mounter) { - m.Mux = mux - } -} - -// Decoder sets the decoder. -func Decoder(dec decoder) Option { - return func(m *Mounter) { - m.Decoder = dec - } -} - -// Encoder sets the encoder. -func Encoder(enc encoder) Option { - return func(m *Mounter) { - m.Encoder = enc - } -} - -// ErrorHandler sets the error handler. -func ErrorHandler(eh errorHandler) Option { - return func(m *Mounter) { - m.ErrorHandler = eh - } -} - -// Formatter sets the error handler. -func Formatter(fm formatter) Option { - return func(m *Mounter) { - m.Formatter = fm - } -} - -// NewMounter constructs a mounter of the goa endpoints. -func NewMounter(opts ...Option) *Mounter { - ret := &Mounter{ - Mux: goahttp.NewMuxer(), - Middleware: []middleware{}, - Decoder: goahttp.RequestDecoder, - Encoder: goahttp.ResponseEncoder, - ErrorHandler: func(ctx context.Context, w http.ResponseWriter, err error) { - log.Printf("ERROR: %v", err) - }, - } - for _, opt := range opts { - opt(ret) - } - return ret -} - -// MountEndpoint mounts an endpoint handler and it's middleware. -func (m *Mounter) MountEndpoint(builder HandlerBuilder, mounter HandlerMounter, endpoint goa.Endpoint, middlewares ...middleware) { - handler := builder(endpoint, m.Mux, m.Decoder, m.Encoder, m.ErrorHandler, m.Formatter) - for _, v := range middlewares { - handler = v(handler) - } - mounter(m.Mux, handler) -} - -type EndpointModular struct { - Builder HandlerBuilder - Mounter HandlerMounter - Endpoint goa.Endpoint - EndpointMiddleware []middleware -} - -func (m *Mounter) Mount(e EndpointModular) { - m.MountEndpoint(e.Builder, e.Mounter, e.Endpoint, e.EndpointMiddleware...) -} - -// Use sets the middleware. -func (m *Mounter) Use(middleware func(http.Handler) http.Handler) { - m.Middleware = append(m.Middleware, middleware) -} - -func (m *Mounter) Handler() http.Handler { - var h http.Handler = m.Mux - for _, v := range m.Middleware { - h = v(h) - } - return h -} - -func (m *Mounter) ServeHTTP(w http.ResponseWriter, r *http.Request) { - var h http.Handler = m.Mux - for _, v := range m.Middleware { - h = v(h) - } - h.ServeHTTP(w, r) -}