apibuildr

package module
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 5, 2022 License: MIT Imports: 13 Imported by: 0

README

ApiBuildr

apibuildr is a commandline tool for creating rest apis in golang language.

apibuildr makes it easy to generate boilerplate code while adding rest apis.

It is not a framework, it uses gorilla mux server internally.

Installing apibuildr
go install github.com/focks/apibuildr/apibuildr@latest
Starting A Project

Apibuildr creates a project directory suitable for a monorepo. The created repo/project would be suitable for housing multiple microservices in it.

apibuildr startProject <project-name> --package example.com/api
Adding Your First Microservice

It will create a rest api server with no endpoints.

apibuildr addApp <microservice-name>
Adding the first Api

Get into the desired microservice where you want the api to be added.

apibuildr addApi <api-name> -p /v1/hello -m POST 

-p or --path represents the api path
-m or --method is the api method (by default it is get)

Contributing

please feel free to fork this project and raise PRs. Please include feature requests into todos.txt file.

NOTE this repository is under development. please feel free to fork and raise pull requests.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApiRequestCtx

func ApiRequestCtx(c context.Context, api string) context.Context

func Contextual

func Contextual(ctx context.Context, errs ...error) []zap.Field

func FourZeroFour

func FourZeroFour() http.Handler

func GetApiName

func GetApiName(ctx context.Context) string

func GetClientID

func GetClientID(ctx context.Context) string

func GetClientSecret

func GetClientSecret(ctx context.Context) string

func GetHost added in v0.0.3

func GetHost(ctx context.Context) string

func GetRequestID

func GetRequestID(ctx context.Context) string

func GetToken

func GetToken(ctx context.Context) string

func GetUserID

func GetUserID(ctx context.Context) string

func HandleError

func HandleError(ctx context.Context, w http.ResponseWriter, err error)

func HandleInternalError

func HandleInternalError(ctx context.Context, w http.ResponseWriter, err error)

func ReadRequestBody added in v0.0.3

func ReadRequestBody(ctx context.Context, r *http.Request, out interface{}) error

Types

type ApiError added in v0.0.3

type ApiError struct {
	Message    string            `json:"message"`
	ApiCode    string            `json:"api_code"`
	ApiName    string            `json:"api_name"`
	RequestId  string            `json:"request_id"`
	Cause      error             `json:"-"`
	StatusCode int               `json:"status_code"`
	Errors     map[string]string `json:"errors"`
}

func NewApiError added in v0.0.3

func NewApiError(status int) *ApiError

func (ApiError) Error added in v0.0.3

func (e ApiError) Error() string

func (*ApiError) Unwrap added in v0.0.3

func (e *ApiError) Unwrap() error

func (*ApiError) WithApiCode added in v0.0.3

func (e *ApiError) WithApiCode(code string) *ApiError

func (*ApiError) WithApiName added in v0.0.3

func (e *ApiError) WithApiName(api string) *ApiError

func (*ApiError) WithCause added in v0.0.3

func (e *ApiError) WithCause(cause *ApiError) *ApiError

func (*ApiError) WithMessage added in v0.0.3

func (e *ApiError) WithMessage(msg string) *ApiError

func (*ApiError) WithRequestId added in v0.0.3

func (e *ApiError) WithRequestId(rid string) *ApiError

type ApiFoul

type ApiFoul struct {
	ApiName    string `json:"api_name"`
	Message    string `json:"message"`
	Cause      error  `json:"-"`
	RequestId  string `json:"request_id"`
	StatusCode int    `json:"status_code"`
	DomainCode string `json:"domain_codes"`
}

func New

func New(msg string) *ApiFoul

func NewFoul added in v0.0.2

func NewFoul(msg string) *ApiFoul

Deprecated

func (ApiFoul) Error

func (f ApiFoul) Error() string

func (*ApiFoul) UnWrap added in v0.0.3

func (e *ApiFoul) UnWrap() error

func (*ApiFoul) WithApiName

func (f *ApiFoul) WithApiName(name string) *ApiFoul

func (*ApiFoul) WithCause

func (f *ApiFoul) WithCause(cause error) *ApiFoul

func (*ApiFoul) WithDomainCode

func (f *ApiFoul) WithDomainCode(code string) *ApiFoul

func (*ApiFoul) WithMessage

func (f *ApiFoul) WithMessage(msg string) *ApiFoul

func (*ApiFoul) WithStatusCode

func (f *ApiFoul) WithStatusCode(status int) *ApiFoul

type ApiHandler

type ApiHandler struct {
	Name       string
	Path       string
	Method     string
	HandleFunc http.HandlerFunc
}

func (ApiHandler) RegisterToRouter

func (api ApiHandler) RegisterToRouter(router *mux.Router)

type ContextKey

type ContextKey int
const (
	ApiName ContextKey = iota

	Token

	ClientID

	ClientSecret

	RequestID

	UserID

	Host
)

type ErrorResponse

type ErrorResponse struct {
	Message   string   `json:"message"`
	ApiCode   string   `json:"error"`
	RequestId string   `json:"request-id"`
	ApiPath   string   `json:"api"`
	Headers   []string `json:"headers"`
}

type OkResponse

type OkResponse struct {
	Status string `json:"status"`
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL