Skip to content
Snippets Groups Projects
Commit 20e3225f authored by Yordan Kinkov's avatar Yordan Kinkov
Browse files

Merge branch '1-goa-skeleton' into 'main'

Service skeleton with health check endpoints

Closes #1

See merge request !1
parents 2336f102 2dc39ba5
Branches
Tags
1 merge request!1Service skeleton with health check endpoints
Pipeline #49699 passed
Showing
with 1103 additions and 0 deletions
// Code generated by goa v3.7.0, DO NOT EDIT.
//
// health HTTP server types
//
// Command:
// $ goa gen code.vereign.com/gaiax/tsa/cache/design
package server
{"swagger":"2.0","info":{"title":"Cache Service","description":"The cache service exposes interface for working with Redis.","version":""},"host":"localhost:8080","consumes":["application/json","application/xml","application/gob"],"produces":["application/json","application/xml","application/gob"],"paths":{"/liveness":{"get":{"tags":["health"],"summary":"Liveness health","operationId":"health#Liveness","responses":{"200":{"description":"OK response."}},"schemes":["http"]}},"/readiness":{"get":{"tags":["health"],"summary":"Readiness health","operationId":"health#Readiness","responses":{"200":{"description":"OK response."}},"schemes":["http"]}}}}
\ No newline at end of file
swagger: "2.0"
info:
title: Cache Service
description: The cache service exposes interface for working with Redis.
version: ""
host: localhost:8080
consumes:
- application/json
- application/xml
- application/gob
produces:
- application/json
- application/xml
- application/gob
paths:
/liveness:
get:
tags:
- health
summary: Liveness health
operationId: health#Liveness
responses:
"200":
description: OK response.
schemes:
- http
/readiness:
get:
tags:
- health
summary: Readiness health
operationId: health#Readiness
responses:
"200":
description: OK response.
schemes:
- http
// Code generated by goa v3.7.0, DO NOT EDIT.
//
// openapi client HTTP transport
//
// Command:
// $ goa gen code.vereign.com/gaiax/tsa/cache/design
package client
import (
"net/http"
goahttp "goa.design/goa/v3/http"
)
// Client lists the openapi service endpoint HTTP clients.
type Client struct {
// 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 openapi 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{
RestoreResponseBody: restoreBody,
scheme: scheme,
host: host,
decoder: dec,
encoder: enc,
}
}
// Code generated by goa v3.7.0, DO NOT EDIT.
//
// openapi HTTP client encoders and decoders
//
// Command:
// $ goa gen code.vereign.com/gaiax/tsa/cache/design
package client
// Code generated by goa v3.7.0, DO NOT EDIT.
//
// HTTP request path constructors for the openapi service.
//
// Command:
// $ goa gen code.vereign.com/gaiax/tsa/cache/design
package client
// Code generated by goa v3.7.0, DO NOT EDIT.
//
// openapi HTTP client types
//
// Command:
// $ goa gen code.vereign.com/gaiax/tsa/cache/design
package client
// Code generated by goa v3.7.0, DO NOT EDIT.
//
// HTTP request path constructors for the openapi service.
//
// Command:
// $ goa gen code.vereign.com/gaiax/tsa/cache/design
package server
// Code generated by goa v3.7.0, DO NOT EDIT.
//
// openapi HTTP server
//
// Command:
// $ goa gen code.vereign.com/gaiax/tsa/cache/design
package server
import (
"context"
"net/http"
openapi "code.vereign.com/gaiax/tsa/cache/gen/openapi"
goahttp "goa.design/goa/v3/http"
)
// Server lists the openapi service endpoint HTTP handlers.
type Server struct {
Mounts []*MountPoint
GenHTTPOpenapi3JSON http.Handler
Swagger http.Handler
}
// ErrorNamer is an interface implemented by generated error structs that
// exposes the name of the error as defined in the design.
type ErrorNamer interface {
ErrorName() string
}
// 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 openapi 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 *openapi.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(err error) goahttp.Statuser,
fileSystemGenHTTPOpenapi3JSON http.FileSystem,
fileSystemSwagger http.FileSystem,
) *Server {
if fileSystemGenHTTPOpenapi3JSON == nil {
fileSystemGenHTTPOpenapi3JSON = http.Dir(".")
}
if fileSystemSwagger == nil {
fileSystemSwagger = http.Dir(".")
}
return &Server{
Mounts: []*MountPoint{
{"./gen/http/openapi3.json", "GET", "/swagger-ui/openapi.json"},
{"./swagger/", "GET", "/swagger-ui"},
},
GenHTTPOpenapi3JSON: http.FileServer(fileSystemGenHTTPOpenapi3JSON),
Swagger: http.FileServer(fileSystemSwagger),
}
}
// Service returns the name of the service served.
func (s *Server) Service() string { return "openapi" }
// Use wraps the server handlers with the given middleware.
func (s *Server) Use(m func(http.Handler) http.Handler) {
}
// Mount configures the mux to serve the openapi endpoints.
func Mount(mux goahttp.Muxer, h *Server) {
MountGenHTTPOpenapi3JSON(mux, goahttp.Replace("", "/./gen/http/openapi3.json", h.GenHTTPOpenapi3JSON))
MountSwagger(mux, goahttp.Replace("/swagger-ui", "/./swagger/", h.Swagger))
}
// Mount configures the mux to serve the openapi endpoints.
func (s *Server) Mount(mux goahttp.Muxer) {
Mount(mux, s)
}
// MountGenHTTPOpenapi3JSON configures the mux to serve GET request made to
// "/swagger-ui/openapi.json".
func MountGenHTTPOpenapi3JSON(mux goahttp.Muxer, h http.Handler) {
mux.Handle("GET", "/swagger-ui/openapi.json", h.ServeHTTP)
}
// MountSwagger configures the mux to serve GET request made to "/swagger-ui".
func MountSwagger(mux goahttp.Muxer, h http.Handler) {
mux.Handle("GET", "/swagger-ui/", h.ServeHTTP)
mux.Handle("GET", "/swagger-ui/*filepath", h.ServeHTTP)
}
// Code generated by goa v3.7.0, DO NOT EDIT.
//
// openapi HTTP server types
//
// Command:
// $ goa gen code.vereign.com/gaiax/tsa/cache/design
package server
{"openapi":"3.0.3","info":{"title":"Cache Service","description":"The cache service exposes interface for working with Redis.","version":"1.0"},"servers":[{"url":"http://localhost:8080","description":"Cache Server"}],"paths":{"/liveness":{"get":{"tags":["health"],"summary":"Liveness health","operationId":"health#Liveness","responses":{"200":{"description":"OK response."}}}},"/readiness":{"get":{"tags":["health"],"summary":"Readiness health","operationId":"health#Readiness","responses":{"200":{"description":"OK response."}}}}},"components":{},"tags":[{"name":"health","description":"Health service provides health check endpoints."}]}
\ No newline at end of file
openapi: 3.0.3
info:
title: Cache Service
description: The cache service exposes interface for working with Redis.
version: "1.0"
servers:
- url: http://localhost:8080
description: Cache Server
paths:
/liveness:
get:
tags:
- health
summary: Liveness health
operationId: health#Liveness
responses:
"200":
description: OK response.
/readiness:
get:
tags:
- health
summary: Readiness health
operationId: health#Readiness
responses:
"200":
description: OK response.
components: {}
tags:
- name: health
description: Health service provides health check endpoints.
// Code generated by goa v3.7.0, DO NOT EDIT.
//
// openapi client
//
// Command:
// $ goa gen code.vereign.com/gaiax/tsa/cache/design
package openapi
import (
goa "goa.design/goa/v3/pkg"
)
// Client is the "openapi" service client.
type Client struct {
}
// NewClient initializes a "openapi" service client given the endpoints.
func NewClient(goa.Endpoint) *Client {
return &Client{}
}
// Code generated by goa v3.7.0, DO NOT EDIT.
//
// openapi endpoints
//
// Command:
// $ goa gen code.vereign.com/gaiax/tsa/cache/design
package openapi
import (
goa "goa.design/goa/v3/pkg"
)
// Endpoints wraps the "openapi" service endpoints.
type Endpoints struct {
}
// NewEndpoints wraps the methods of the "openapi" service with endpoints.
func NewEndpoints(s Service) *Endpoints {
return &Endpoints{}
}
// Use applies the given middleware to all the "openapi" service endpoints.
func (e *Endpoints) Use(m func(goa.Endpoint) goa.Endpoint) {
}
// Code generated by goa v3.7.0, DO NOT EDIT.
//
// openapi service
//
// Command:
// $ goa gen code.vereign.com/gaiax/tsa/cache/design
package openapi
// The openapi service serves the OpenAPI(v3) definition.
type Service interface {
}
// 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 = "openapi"
// 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 = [0]string{}
go.mod 0 → 100644
module code.vereign.com/gaiax/tsa/cache
go 1.17
require (
code.vereign.com/gaiax/tsa/golib v0.0.0-20220321093827-5fdf8f34aad9
github.com/kelseyhightower/envconfig v1.4.0
go.uber.org/zap v1.21.0
goa.design/goa/v3 v3.7.0
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
)
require (
github.com/dimfeld/httppath v0.0.0-20170720192232-ee938bf73598 // indirect
github.com/dimfeld/httptreemux/v5 v5.4.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gopherjs/gopherjs v0.0.0-20220221023154-0b2280d3ff96 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/jtolds/gls v4.20.0+incompatible // indirect
github.com/manveru/faker v0.0.0-20171103152722-9fbc68a78c4d // indirect
github.com/sergi/go-diff v1.2.0 // indirect
github.com/smartystreets/assertions v1.2.1 // indirect
github.com/zach-klippenstein/goregen v0.0.0-20160303162051-795b5e3961ea // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect
golang.org/x/sys v0.0.0-20220317061510-51cd9980dadf // indirect
golang.org/x/tools v0.1.10 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)
go.sum 0 → 100644
This diff is collapsed.
#!/bin/bash
set -e
# preserve the value of GOFLAGS
STORED_GOFLAGS=$(go env GOFLAGS)
# force goa to not use vendored deps during generation
go env -w GOFLAGS=-mod=mod
# execute goa code generation
goa gen code.vereign.com/gaiax/tsa/cache/design
# restore the value of GOFLAGS
go env -w GOFLAGS=$STORED_GOFLAGS
package config
import "time"
type Config struct {
HTTP httpConfig
LogLevel string `envconfig:"LOG_LEVEL" default:"INFO"`
}
type httpConfig struct {
Host string `envconfig:"HTTP_HOST"`
Port string `envconfig:"HTTP_PORT" default:"8080"`
IdleTimeout time.Duration `envconfig:"HTTP_IDLE_TIMEOUT" default:"120s"`
ReadTimeout time.Duration `envconfig:"HTTP_READ_TIMEOUT" default:"10s"`
WriteTimeout time.Duration `envconfig:"HTTP_WRITE_TIMEOUT" default:"10s"`
}
package service
import (
goahttp "goa.design/goa/v3/http"
goa "goa.design/goa/v3/pkg"
"code.vereign.com/gaiax/tsa/golib/errors"
)
func NewErrorResponse(err error) goahttp.Statuser {
if err == nil {
return nil
}
var newerr *errors.Error
switch e := err.(type) {
case *errors.Error:
newerr = e
case *goa.ServiceError:
// Use goahttp.ErrorResponse to determine error kind
goaerr := goahttp.NewErrorResponse(e)
kind := errors.GetKind(goaerr.StatusCode())
newerr = &errors.Error{
ID: e.ID,
Kind: kind,
Message: e.Message,
Err: e,
}
default:
newerr = &errors.Error{
ID: errors.NewID(),
Kind: errors.Internal,
Message: e.Error(),
Err: e,
}
}
return newerr
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment