apibuildr

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2022 License: MIT Imports: 9 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 get github.com/focks/apibuildr
Initializing a project
apibuildr init .

It will create a rest api server with no endpoints.

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

Adding the first Api
apibuildr addApi apiName -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.

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 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)

Types

type ApiFoul

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

func NewFoul added in v0.0.2

func NewFoul(msg string) *ApiFoul

func (ApiFoul) Error

func (f ApiFoul) Error() string

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
)

type ErrorResponse

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

type Foul

type Foul interface {
	Error() string
}

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