wok

package module
v0.0.0-...-2dc5899 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2024 License: GPL-3.0 Imports: 10 Imported by: 0

README

Wok.

Wok is a simple http server written in Go. Wok aims to help Gophers create simple applications without the need overengineer their projects. Wok doesn't have any fancy features or complicated routing procedures. Its pure Go and doesn't require CGO to be enabled.

I originally set out to make a multi featured http server. Wok originally was a way to package multiple services for developers to configure out of the box. But, Wok feels right when its as simple as possible.

Wok is my passion project. As time goes on I will add and remove features as I need them. If you feel like something should be added or changed in Wok feel free to make a PR. But I cannot promise that every feature will be added.

Wok is not, nor will it probably every be as great as things like Fiber and other projects like it. But I wanted something to build and call my own when I make applications, even if that means I can't achieve the bleeding edge.

Currently Wok is under development and I will commit breaking changes without warning.

Simple Usage:

package main

import (
	"github.com/averystampp/wok"
)

func main() {
	
	app := wok.NewWok(":5000")
	
	app.Get("/", HelloFromWok)

	app.StartWok()
}

func HelloFromWok(ctx wok.Context) error {
	ctx.SendString("Hello from Wok!")
	return nil
}

Use a database (Wok only supports postgres):

package main

import (
	"github.com/averystampp/wok"
)

func main() {
	app := wok.NewWok(":5000")
	
	conf := &wok.Config{
		Host:            "{YOUR_POSTGRES_HOST}",
		Port:            5432,
		User:            "{YOUR_POSTGRES_USER}",
		Password:        "{YOUR_POSTGRES_PASSWORD}",
		Dbname:          "{DATABASE_NAME}",
		MigrationFolder: "./migrations",
	}
	app.WithDatabase(conf)

	app.Get("/", HelloFromWok)
	app.StartWok(dbconfig)

}

func HelloFromWok(ctx wok.Context) error {
	ctx.SendString("Hello from Wok!")
	return nil
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DB *sql.DB

Functions

func Connect

func Connect(config *DatabaseOpts)

func DropTable

func DropTable()

drops the users table, nice function to have when testing and you want to start fresh

Types

type Context

type Context struct {
	Resp http.ResponseWriter
	Req  *http.Request
	// contains filtered or unexported fields
}

Context controls ResponseWriter and pointer to Request, used to extend methods

func (*Context) Database

func (ctx *Context) Database() (*sql.DB, error)

type DatabaseOpts

type DatabaseOpts struct {
	Host            string
	Port            int
	SSL             bool
	User            string
	Password        string
	Dbname          string
	MigrationFolder string
}

type Handler

type Handler func(Context) error

Wok enforces its own handler to return an error, then wraps it into an http handler converter

type Route

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

type Router

type Router struct {
	CertFile string
	KeyFile  string
	// contains filtered or unexported fields
}

func NewRouter

func NewRouter() *Router

func (*Router) Get

func (r *Router) Get(path string, h ...Handler)

func (*Router) Head

func (r *Router) Head(path string, h ...Handler)

func (*Router) Options

func (r *Router) Options(path string, h ...Handler)

func (*Router) Patch

func (r *Router) Patch(path string, h ...Handler)

func (*Router) Post

func (r *Router) Post(path string, h ...Handler)

func (*Router) Put

func (r *Router) Put(path string, h ...Handler)

func (*Router) ServeHTTP

func (r *Router) ServeHTTP(wr http.ResponseWriter, req *http.Request)

func (*Router) SetRootDir

func (r *Router) SetRootDir(root string)

func (*Router) StartRouter

func (r *Router) StartRouter(port string)

func (*Router) Trace

func (r *Router) Trace(path string, h ...Handler)

func (*Router) With

func (r *Router) With(h ...Handler)

func (*Router) WithDatabase

func (r *Router) WithDatabase(opts *DatabaseOpts)

Jump to

Keyboard shortcuts

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