https://github.com/mikigal/webserver
Lightweight own HTTP implementation with MVC in Go
https://github.com/mikigal/webserver
go golang http-protocol lightweight-mvc-framework mvc webserver
Last synced: about 1 month ago
JSON representation
Lightweight own HTTP implementation with MVC in Go
- Host: GitHub
- URL: https://github.com/mikigal/webserver
- Owner: mikigal
- Created: 2019-08-03T12:19:54.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-08-04T23:11:00.000Z (over 5 years ago)
- Last Synced: 2025-02-06T02:44:36.323Z (3 months ago)
- Topics: go, golang, http-protocol, lightweight-mvc-framework, mvc, webserver
- Language: Go
- Homepage:
- Size: 46.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.MD
Awesome Lists containing this project
README
# webserver
Lightweight own (without net/http) HTTP protocol implementation with basic MVC in Go## How to use?
#### Example with Context usage: [\*Click\*](main.go)
```go
func main() {
server := webserver.WebServer {
Address: "localhost:1234", // Address for server
WebsiteDir: "./example_website", // Working directory with website files
}// If there isn't route for URL server serve file from WebsiteDir, for / it's index.html
server.Route(test, "/test", "GET", "POST") // Route "/test" to function "root" for HTTP methods GET and POST
server.ErrorHandler(404, customError) // Redirect all 404 errors to customError function
server.Start() // Start server!
}func test(ctx *webserver.Context) {
// Do something awesome//ctx.Redirect(http.StatusMovedPermanently, "/anotherPath")
//ctx.HTML(200, "Test
")
//ctx.JSON(200, "{\"test\": \"abc\"}")
//ctx.Error(403, "")
ctx.File(200, "test.html")
}func customError(ctx *webserver.Context) {
ctx.JSON(404, "{\"error\": \"not_found\"}")
}
```