goldship

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2024 License: MIT Imports: 9 Imported by: 0

README

GoFo

This Go module is a collection of tools designed to support the development of REST APIs. It provides a range of functionalities that streamline the process of creating, testing, and maintaining RESTful services.

Prerequisites

Before using this module, please ensure that you have the following libraries installed:

  • Echo: A high performance, extensible, minimalist web framework for Go.
  • Validator: A Go Struct and Field validation, including Cross Field, Cross Struct, Map, Slice and Array diving.
  • Zap: A blazing fast, structured, leveled logging library.

These libraries are integral to the functionality of this module and are required for its operation.

Installation

To install this module, you can use the go get command:

go get github.com/yukanamori/gofo

Usage

To use this module in your Go code, import it like this:

import "github.com/yukanamori/gofo"

Then, you can call the functions provided by the module.

Contributing

Contributions are welcome. Please feel free to submit a pull request or open an issue.

License

This module is licensed under the MIT License. See the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrEmptyPassword is returned when the password is empty
	ErrEmptyPassword = errors.New("password is empty")
)
View Source
var (
	// RFC3339Milli is a time.RFC3339 with millisecond precision
	RFC3339Milli = "2006-01-02T15:04:05.999Z07:00"
)

Functions

func BindAndValidate

func BindAndValidate(c echo.Context, i interface{}) error

BindAndValidate binds and validates the input

func BuildRequestLoggerConfig

func BuildRequestLoggerConfig(logger *zap.Logger) middleware.RequestLoggerConfig

BuildRequestLoggerConfig returns a new middleware.RequestLoggerConfig

func HashPassword

func HashPassword(password string) ([]byte, error)

HashPassword hashes the password

func NewBadRequestError

func NewBadRequestError(code int, message string) *echo.HTTPError

NewBadRequestError returns a new BadRequestError

func NewDevelopment

func NewDevelopment() *zap.Logger

NewDevelopment returns a new development logger

func NewProduction

func NewProduction(debug bool) *zap.Logger

NewProduction returns a new production loggers If debug is true, the logger will be set to debug level

Types

type AppEnv

type AppEnv string

AppEnv is the application environment

const (
	// Development is the development environment
	Development AppEnv = "development"
	// Test is the test environment
	Test AppEnv = "test"
	// Production is the production environment
	Production AppEnv = "production"
)

func (AppEnv) IsDevelopment

func (e AppEnv) IsDevelopment() bool

IsDevelopment returns true if the environment is development

func (AppEnv) IsProduction

func (e AppEnv) IsProduction() bool

IsProduction returns true if the environment is production

func (AppEnv) IsTest

func (e AppEnv) IsTest() bool

IsTest returns true if the environment is test

type BadRequestError

type BadRequestError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

BadRequestError is a custom error type for bad request

func (*BadRequestError) Error

func (e *BadRequestError) Error() string

Error returns the error message

type Validator

type Validator struct {
	// contains filtered or unexported fields
}

Validator is a wrapper around go-playground/validator/v10

func NewValidator

func NewValidator() *Validator

NewValidator returns a new Validator

func (*Validator) Validate

func (v *Validator) Validate(i interface{}) error

Validate validates the input using the validator

Jump to

Keyboard shortcuts

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