Categorygithub.com/lordtor/go-base-api
repositorypackage
0.3.1
Repository: https://github.com/lordtor/go-base-api.git
Documentation: pkg.go.dev

# README

API

Get

    go get -u github.com/lordtor/go-base-api/api

Configuration

ParameterRequiredTypeDefaultDescription
ListenPortint8080Service port
WriteTimeoutint30WriteTimeout is a time limit imposed on client connecting to the server via http from the time the server has completed reading the request header up to the time it has finished writing the response.
ReadTimeoutint30ReadTimeout is a timing constraint on the client http request imposed by the server from the moment of initial connection up to the time the entire request body has been read.
GracefulTimeoutint15Shutdown gracefully shuts down the server without interrupting any active connections. Shutdown works by first closing all open listeners, then closing all idle connections, and then waiting indefinitely for connections to return to idle and then shut down. If the provided context expires before the shutdown is complete, Shutdown returns the context’s error, otherwise it returns any error returned from closing the Server’s underlying Listener(s).
IdleTimeoutint60This timeout is also applicable to a connection pool. Idle Connection Timeout specifies how much time an unused connection should be kept around.
SwaggerboolfalseEnable swagger
PrometheusboolfalseEnable metrics Prometheus
LocalSwaggerboolfalseUse for test swagger on localhost or local IP (dev mode)
Schemastringhttpbase schema
Appstring*nilService name
Hoststring*nilService host name
ApiHoststringnilIf not set auto value
AllowedOrigins[]string*Set allowed origins (CORS)
AllowedHeaders[]string"X-Requested-With", "Content-Type", "Authorization", "SERVICE-AGENT", "Access-Control-Allow-Methods", "Date", "X-FORWARDED-FOR", "Accept", "Content-Length", "Accept-Encoding", "Service-Agent"Set allowed headers (CORS)
AllowedMethods[]string"GET", "POST", "PUT", "PATCH", "HEAD", "OPTIONS"Set allowed methods (CORS)
AppConfiginterface{}*nilMain config for show by method /env use json json:"-" anotation for secret data.

Example

    cd cmd
    go run main.go

Update swagger doc

  • Get swag
    go install github.com/swaggo/swag/cmd/swag@latest
  • Documentation update:
    swag init  --parseDependency --generatedTime --parseInternal  --parseDepth 5