gowok

package module
v0.3.98 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2025 License: MIT Imports: 27 Imported by: 27

README

Gowok is a library that contains a lot of functions that help you to build Go project.

It has some utilities like:

  • config loader,
  • project bootstrapper,
  • HTTP response builder,
  • nil safety,
  • password hash, and so on.

Getting Started

Installation

Run this command inside your project.

go get github.com/gowok/gowok

Import in Project

In your main.go, write code like following example:

package main

import "github.com/gowok/gowok"

func main() {
	gowok.Get().Run()
}

Create Configuration

  1. Create a YAML file named config.yaml.
  2. Then write this.
web:
  enabled: true
  host: :8080

Running the Project

Run this command inside your project.

go run main.go

Or if config file not on root dir, use flag --config

go run main.go --config=folder/gowok.yaml

It will show output like this:

2025/01/13 10:43:09 INFO starting web

Your project now ready to use 🔥

Let's try to send a request using curl!

curl localhost:8080

It will show output like this:

404 page not found

It means that your project already run. It can receive actual request and give response to it.

How to Contribute

Feel free to raise an issue or lovely pull request 😊

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DD

func DD(input any) error

func FlagParse

func FlagParse()

func Flags

func Flags() *flags

func Handler added in v0.3.94

func Handler(handler func(ctx *WebCtx) error) http.HandlerFunc

func HandlerSse added in v0.3.95

func HandlerSse(handler func(ctx *WebSseCtx)) http.HandlerFunc

func Hooks

func Hooks() *runtime.Hooks

func HttpAccepted

func HttpAccepted(w http.ResponseWriter, body ...any)

func HttpBadRequest

func HttpBadRequest(w http.ResponseWriter, body any)

func HttpConflict

func HttpConflict(w http.ResponseWriter, body ...any)

func HttpCreated

func HttpCreated(w http.ResponseWriter, body ...any)

func HttpForbidden

func HttpForbidden(w http.ResponseWriter)

func HttpInternalServerError

func HttpInternalServerError(w http.ResponseWriter, body ...any)

func HttpNoContent

func HttpNoContent(w http.ResponseWriter)

func HttpNotFound

func HttpNotFound(w http.ResponseWriter)

func HttpOk

func HttpOk(w http.ResponseWriter, body ...any)

func HttpUnauthorized

func HttpUnauthorized(w http.ResponseWriter)

func Router added in v0.3.92

func Router() *ngamux.HttpServeMux

func Run added in v0.3.94

func Run(config ...Config)

func Server added in v0.3.92

func Server() *http.Server

func ToPtr

func ToPtr[T any](v T) *T

Types

type Config

type Config struct {
	Key      string                 `json:"key,omitempty"`
	Web      config.Web             `json:"web,omitempty"`
	Grpc     config.Grpc            `json:"grpc,omitempty"`
	Security config.Security        `json:"security,omitempty"`
	SQLs     map[string]config.SQL  `json:"sql,omitempty"`
	Smtp     map[string]config.Smtp `json:"smtp,omitempty"`
	Others   map[string]any         `json:"others,omitempty"`

	EnvFile   string `json:"env_file,omitempty"`
	IsTesting bool   `json:"is_testing,omitempty"`
	Forever   bool   `json:"-"`
}

type ConfigureFunc

type ConfigureFunc func(*Project)

type Pagination

type Pagination[T any] struct {
	Page        int `query:"page" json:"page"`
	PerPage     int `query:"per_page" json:"per_page"`
	TotalRecord int `json:"total_record"`

	Filter map[string]any    `query:"filter" json:"filter"`
	Fields []string          `query:"fields" json:"fields"`
	Sort   map[string]string `query:"sort" json:"sort"`

	Data []T `json:"data"`
}

func PaginationFromReq

func PaginationFromReq[T any](r *http.Request) Pagination[T]

func (Pagination[T]) MarshalJSON

func (p Pagination[T]) MarshalJSON() ([]byte, error)

func (*Pagination[T]) SetData

func (p *Pagination[T]) SetData(data ...T)

func (Pagination[T]) Skip

func (p Pagination[T]) Skip() int

func (Pagination[T]) TotalPage

func (p Pagination[T]) TotalPage() float64

type Project

type Project struct {
	Config    *Config
	ConfigMap map[string]any
	// contains filtered or unexported fields
}

func Configures added in v0.3.94

func Configures(configures ...ConfigureFunc) *Project

func Get

func Get(config ...Config) *Project

func (*Project) Configures

func (p *Project) Configures(configures ...ConfigureFunc) *Project

func (*Project) Run

func (p *Project) Run()

type WebCtx added in v0.3.95

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

func (WebCtx) Deadline added in v0.3.95

func (ctx WebCtx) Deadline() (time.Time, bool)

func (WebCtx) Done added in v0.3.95

func (ctx WebCtx) Done() <-chan struct{}

func (WebCtx) Err added in v0.3.95

func (ctx WebCtx) Err() error

func (WebCtx) Req added in v0.3.95

func (ctx WebCtx) Req() *web.Request

func (WebCtx) Res added in v0.3.95

func (ctx WebCtx) Res() *web.Response

func (*WebCtx) SetContext added in v0.3.95

func (ctx *WebCtx) SetContext(ctxNew context.Context)

func (*WebCtx) SetValue added in v0.3.95

func (ctx *WebCtx) SetValue(key, value any)

func (WebCtx) Value added in v0.3.95

func (ctx WebCtx) Value(key any) any

func (*WebCtx) Write added in v0.3.95

func (ctx *WebCtx) Write(content []byte) (int, error)

type WebSseCtx added in v0.3.95

type WebSseCtx struct {
	*WebCtx
	// contains filtered or unexported fields
}

func (*WebSseCtx) Emit added in v0.3.96

func (ctx *WebSseCtx) Emit(event string, message []byte) error

func (*WebSseCtx) Flush added in v0.3.95

func (ctx *WebSseCtx) Flush()

func (*WebSseCtx) Publish added in v0.3.95

func (ctx *WebSseCtx) Publish(message []byte) error

func (*WebSseCtx) PublishRaw added in v0.3.96

func (ctx *WebSseCtx) PublishRaw(format string, a ...any) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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