modulepackage
0.0.0-20201210133501-58bf0a829f21
Repository: https://github.com/soongo/soon.git
Documentation: pkg.go.dev
# README
Soon Web Framework
Soon is a web framework written in Go (Golang). It features an expressjs-like API.
Installation
To install Soon
, you need to install Go and set your Go workspace first.
The first need Go installed (version 1.11+ is required), then you can use the below Go command to install Soon
.
$ go get -u github.com/soongo/soon
Quick Start
package main
import (
"github.com/soongo/soon"
)
// an example middleware
func logger(c *soon.Context) {
// do something before
c.Next()
// do something after
}
func main() {
// soon.SetMode(soon.DebugMode) // enable soon framework debug mode
// Create an app with default router
app := soon.New()
app.Use(logger) // use middleware
app.GET("/", func(c *soon.Context) {
c.Send("Hello World")
})
app.GET("/:foo", func(c *soon.Context) {
c.Send(c.Params().Get("foo"))
})
// an example error handler
app.Use(func(v interface{}, c *soon.Context) {
msg := "Internal Server Error"
switch err := v.(type) {
case error:
msg = err.Error()
case string:
msg = err
}
c.Status(500)
c.Send(msg)
})
app.Run() // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
}
# Functions
DevLog is a built-in middleware function in Soon.
DisableBindValidation closes the default validator.
EnableJsonDecoderDisallowUnknownFields sets true for binding.EnableDecoderDisallowUnknownFields to call the DisallowUnknownFields method on the JSON Decoder instance.
EnableJsonDecoderUseNumber sets true for binding.EnableDecoderUseNumber to call the UseNumber method on the JSON Decoder instance.
IsDebugging returns true if the framework is running in debug mode.
Mode returns currently soon mode.
New creates a Soon application.
NewContext returns an instance of Context object.
NewRequest returns an instance of Request object.
NewRouter returns a new initialized Router with default configuration.
SetMode sets soon mode according to input string.
Static is a built-in middleware function in Soon.
# Constants
BodyBytesKey indicates a default body bytes key.
DebugMode indicates soon mode is debug.
EnvSoonMode indicates environment name for soon mode.
HTTPMethodAll means any http method.
ReleaseMode indicates soon mode is release.
TestMode indicates soon mode is test.
Version is the current version of Soon framework.
# Variables
DefaultErrorWriter is the default io.Writer used by Soon to debug errors.
DefaultWriter is the default io.Writer used by Soon for debug output.
# Structs
App represents an application with Soon framework.
Context is the most important part of soon.
Request is a wrapper for http.Request.
Router is a http.Handler which can be used to dispatch requests to different handler functions.
RouterOption contains options for router, such as `Sensitive` and `Strict`.
# Interfaces
ResponseWriter interface.
# Type aliases
ErrorHandle handles the error generated in route handler, and dispatch error and context objects into the error handler.
Handle is the handler function of router, router use it to handle matched http request, and dispatch a context object into the handler.
No description provided by the author
Params contains all matched url params.