Product Promotion
0x5a.live
for different kinds of informations and explorations.
GitHub - twharmon/goweb: Lightweight web framework based on net/http.
Lightweight web framework based on net/http. Contribute to twharmon/goweb development by creating an account on GitHub.
Visit SiteGitHub - twharmon/goweb: Lightweight web framework based on net/http.
Lightweight web framework based on net/http. Contribute to twharmon/goweb development by creating an account on GitHub.
Powered by 0x5a.live ๐
Goweb
Light weight web framework based on net/http.
Includes
- routing
- middleware
- logging
Goweb aims to
- rely only on the standard library as much as possible
- be flexible
- perform well
Usage
See examples.
Basic
package main
import (
"github.com/twharmon/goweb"
)
func main() {
app := goweb.New()
app.GET("/hello/{name}", hello)
app.Run(":8080")
}
func hello(c *goweb.Context) goweb.Responder {
return c.JSON(http.StatusOK, goweb.Map{
"hello": c.Param("name"),
})
}
Logging
package main
import (
"github.com/twharmon/goweb"
)
func main() {
app := goweb.New()
app.RegisterLogger(newLogger(goweb.LogLevelInfo))
app.GET("/hello/{name}", hello)
app.Run(":8080")
}
func hello(c *goweb.Context) goweb.Responder {
c.LogInfo("param name:", c.Param("name"))
// logs "[INFO] /hello/Gopher param name: Gopher"
return c.JSON(http.StatusOK, goweb.Map{
"hello": c.Param("name"),
})
}
type logger struct{
level goweb.LogLevel
}
func newLogger(level goweb.LogLevel) goweb.Logger {
return &logger{level: level}
}
func (l *logger) Log(c *goweb.Context, logLevel goweb.LogLevel, messages ...interface{}) {
if l.level > logLevel {
return
}
prefix := fmt.Sprintf("[%s] %s", logLevel, c.Request.URL.Path)
messages = append([]interface{}{prefix}, messages...)
log.Println(messages...)
}
Auto TLS
package main
import (
"context"
"errors"
"log"
"net/http"
"github.com/twharmon/goweb"
"golang.org/x/crypto/acme/autocert"
)
func main() {
app := goweb.New()
app.GET("/", func(c *goweb.Context) goweb.Responder {
return c.JSON(http.StatusOK, goweb.Map{
"hello": "world",
})
})
serveTLS(app)
}
func serveTLS(app *goweb.Engine) {
m := &autocert.Manager{
Cache: autocert.DirCache(".certs"),
Prompt: autocert.AcceptTOS,
HostPolicy: func(_ context.Context, host string) error {
if host == "example.com" {
return nil
}
return errors.New("host not configured")
},
}
go http.ListenAndServe(":http", m.HTTPHandler(nil))
s := &http.Server{
Addr: ":https",
TLSConfig: m.TLSConfig(),
Handler: app,
}
log.Fatalln(s.ListenAndServeTLS("", ""))
}
Easily extendable
See serving files, template rendering, tls, and logging for examples.
Documentation
For full documentation see pkg.go.dev.
Benchmarks
BenchmarkGinPlaintext-10 2706439 440.0 ns/op 1040 B/op 9 allocs/op
BenchmarkEchoPlaintext-10 2549317 470.7 ns/op 1024 B/op 10 allocs/op
BenchmarkGowebPlaintext-10 1584044 756.6 ns/op 1456 B/op 16 allocs/op
BenchmarkGorillaPlaintext-10 1000000 1027 ns/op 1744 B/op 17 allocs/op
BenchmarkMartiniPlaintext-10 223416 5364 ns/op 1789 B/op 39 allocs/op
BenchmarkGowebJSON-10 25945 46359 ns/op 50905 B/op 15 allocs/op
BenchmarkEchoJSON-10 25664 46571 ns/op 50641 B/op 10 allocs/op
BenchmarkGorillaJSON-10 25716 46857 ns/op 51115 B/op 16 allocs/op
BenchmarkGinJSON-10 23697 50697 ns/op 100836 B/op 10 allocs/op
BenchmarkMartiniJSON-10 22746 52613 ns/op 52665 B/op 41 allocs/op
BenchmarkGinPathParams-10 914139 1273 ns/op 1849 B/op 25 allocs/op
BenchmarkEchoPathParams-10 889014 1309 ns/op 1865 B/op 25 allocs/op
BenchmarkGowebPathParams-10 627306 1902 ns/op 2570 B/op 33 allocs/op
BenchmarkGorillaPathParams-10 552852 2144 ns/op 2874 B/op 32 allocs/op
BenchmarkMartiniPathParams-10 188500 6215 ns/op 2641 B/op 47 allocs/op
Contribute
Create a pull request to contribute to Goweb.
GoLang Resources
are all listed below.
GitHub - GuilhermeCaruso/anko: :crystal_ball: Simple application watcher
resource
~/github.com
resource
GitHub - jidicula/go-fuzz-action: GitHub Action for Go 1.18 fuzz testing
resource
~/github.com
resource
GitHub - tucnak/climax: Climax is an alternative CLI with the human face
resource
~/github.com
resource
GitHub - lawrencewoodman/roveralls: A Go recursive coverage testing tool
resource
~/github.com
resource
GitHub - nakagami/firebirdsql: Firebird RDBMS sql driver for Go (golang)
resource
~/github.com
resource
GitHub - liweiyi88/onedump: Effortlessly database dump with one command.
resource
~/github.com
resource
GitHub - beefsack/go-astar: Go implementation of the A* search algorithm
resource
~/github.com
resource
GitHub - lxn/walk: A Windows GUI toolkit for the Go Programming Language
resource
~/github.com
resource
GitHub - mongodb/mongo-go-driver: The Official Golang driver for MongoDB
resource
~/github.com
resource
GitHub - bykof/gostradamus: Gostradamus: Better DateTimes for Go ๐ฐ๏ธ
resource
~/github.com
resource
GitHub - mozillazg/go-unidecode: ASCII transliterations of Unicode text.
resource
~/github.com
resource
GitHub - bolknote/go-gd: Go bingings for GD (http://www.boutell.com/gd/)
resource
~/github.com
resource
GitHub - mosajjal/dnsmonster: Passive DNS Capture and Monitoring Toolkit
resource
~/github.com
resource
GitHub - haxpax/gosms: :mailbox_closed: Your own local SMS gateway in Go
resource
~/github.com
resource
GitHub - wajox/gobase: This is a simple skeleton for golang applications
resource
~/github.com
resource
GitHub - VividCortex/gohistogram: Streaming approximate histograms in Go
resource
~/github.com
resource
GitHub - malaschitz/randomForest: Random Forest implementation in golang
resource
~/github.com
resource
GitHub - google/gopacket: Provides packet processing capabilities for Go
resource
~/github.com
resource
GitHub - khezen/evoli: Genetic Algorithm and Particle Swarm Optimization
resource
~/github.com
resource
GitHub - didip/tollbooth: Simple middleware to rate-limit HTTP requests.
resource
~/github.com
resource
GitHub - mustafaakin/gongular: A different approach to Go web frameworks
resource
~/github.com
resource
GitHub - songgao/colorgo: Colorize (highlight) `go build` command output
resource
~/github.com
resource
Made with โค๏ธ
to provide different kinds of informations and resources.