gofusion

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2023 License: MIT Imports: 9 Imported by: 0

README

GoFusion

GoFusion is a simple approach to build web services. Right now, it's just a glue between gin and gorm.

Disclaimer: This project is under development and should not be used in production environments, so use it with caution!

How to use it?

First, get the package to your project:

go get github.com/berkaycubuk/gofusion

Simple example:

package main

func main() {
    // initialize gofusion
    reactor := gofusion.Init()

    // you can access the router with reactor.Router and it's a *gin.Engine, so you can use it like you do with go-gin

    // run the http server at port 4000
    gofusion.Run(reactor, 4000)
}

You may want to use CORS middleware coming with gofusion:

reactor.Router.Use(gofusion.CORSMiddleware())

GoFusion also comes with scheduling thanks to gocron. It is stored in Reactor as Scheduler:

reactor.Scheduler.Every(10).Minutes().Do(func() {
    fmt.Println("Hello!")
})

Validation

GoFusion comes with form validation.

### URI Parameter Validation

ValidateURIParam(paramName string) middleware will validate uri parameter.

Utils

  • RandomString(length int): Generate random string with given lenght.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CORSMiddleware

func CORSMiddleware(origin string) gin.HandlerFunc

func HandleAPIResponse added in v0.2.0

func HandleAPIResponse() gin.HandlerFunc

middleware

func RandomString added in v0.2.0

func RandomString(n int) string

func RespondJSON added in v0.2.0

func RespondJSON(ctx *gin.Context, status int, message string, data interface{})

func Run

func Run(reactor *Reactor, port int)

func Validate added in v0.2.0

func Validate(c *gin.Context, request any) map[string]string

func ValidateURIParam added in v0.2.0

func ValidateURIParam(paramName string) gin.HandlerFunc

middleware

Types

type APIResponse added in v0.2.0

type APIResponse struct {
	Status  int         `json:"status"`
	Message string      `json:"message"`
	Data    interface{} `json:"data,omitempty"`
}

type Reactor

type Reactor struct {
	Router    *gin.Engine
	Scheduler *gocron.Scheduler
}

func Init

func Init() *Reactor

Jump to

Keyboard shortcuts

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