gobase

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2020 License: MIT Imports: 11 Imported by: 0

README

gobase

godoc - documentation go report card codecov - code coverage github action - test

gobase is a web framework with basic settings and structure, wrapping echo.

Installation

go get github.com/cancue/gobase

Example

package main
import (
	"net/http"
	"github.com/cancue/gobase"
	"github.com/labstack/echo/v4/middleware"
)
// Handler
func hello(c gobase.Context) error {
	return c.String(http.StatusOK, "Hello, World!")
}
func main() {
	// Gobase instance
	g := gobase.NewWithConfig(gobase.Config{
		Stage: "local",
		Name: "gobase-example",
		Port: 65535,
		ReadTimeout: 0,
		WriteTimeout: 0,
	})
	// Middleware
	g.Use(middleware.Secure())
	// Routes
	g.GET("/", hello)
	// Start server
	g.Start()
}

Demo

gobase-demo

License

MIT

Documentation

Overview

Package gobase is a web framework with basic settings and structure, wrapping labstack/echo.

Example:

package main
import (
	"net/http"
	"github.com/cancue/gobase"
	"github.com/labstack/echo/v4/middleware"
)
// Handler
func hello(c gobase.Context) error {
	return c.String(http.StatusOK, "Hello, World!")
}
func main() {
	// Gobase instance
	g := gobase.NewWithConfig(gobase.Config{
		Stage: "local",
		Name: "gobase-example",
		Port: 65535,
		ReadTimeout: 0,
		WriteTimeout: 0,
	})
	// Middleware
	g.Use(middleware.Secure())
	// Routes
	g.GET("/", hello)
	// Start server
	g.Start()
}

You may want to check out https://github.com/cancue/gobase-demo

Index

Constants

This section is empty.

Variables

View Source
var (
	// NewHTTPError is an alias for labstack/echo.
	NewHTTPError = echo.NewHTTPError
)
View Source
var (
	// Validator is an alias for go-playground/validator
	Validator *validation.Validate
)

Functions

func Controller

func Controller(obj interface{}) func(echo.Context) error

Controller returns controller from a struct written in suggested form.

func NewInvalidErrorMap

func NewInvalidErrorMap(err error) interface{}

NewInvalidErrorMap returns rich error message.

Types

type Config

type Config struct {
	Stage             string
	Name              string
	Port              string
	ReadTimeout       time.Duration
	WriteTimeout      time.Duration
	HTTPRequestLogger bool
}

Config defines the config for Server.

type Context

type Context echo.Context

Context for controller is an alias for labstack/echo

type Server

type Server struct {
	Config *Config
	Logger *logrus.Logger
	// contains filtered or unexported fields
}

Server is the top-level framework instance.

func New

func New(stage string) *Server

New returns server with Config by config/{stage}.yaml written in suggested form.

func NewWithConfig

func NewWithConfig(config *Config) *Server

NewWithConfig returns server with CustomConfig.

func (*Server) DELETE

func (s *Server) DELETE(path string, controller echo.HandlerFunc, m ...echo.MiddlewareFunc)

DELETE for router is an alias for labstack/echo.

func (*Server) GET

func (s *Server) GET(path string, controller echo.HandlerFunc, m ...echo.MiddlewareFunc)

GET for router is an alias for labstack/echo.

func (*Server) POST

func (s *Server) POST(path string, controller echo.HandlerFunc, m ...echo.MiddlewareFunc)

POST for router is an alias for labstack/echo.

func (*Server) PUT

func (s *Server) PUT(path string, controller echo.HandlerFunc, m ...echo.MiddlewareFunc)

PUT for router is an alias for labstack/echo.

func (*Server) Routes

func (s *Server) Routes() (data []byte, err error)

Routes returns labstack/echo Routes result in marshalled json.

func (*Server) Start

func (s *Server) Start()

Start starts server.

func (*Server) Use

func (s *Server) Use(middleware ...echo.MiddlewareFunc)

Use for middleware is an alias for labstack/echo.

type ValidationError

type ValidationError struct {
	Message       string              `json:"message"`
	InvalidFields []map[string]string `json:"invalidFields"`
}

ValidationError describes the error information in the format for the end user.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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