https://github.com/vaclovas2020/webimizer
Lightweight HTTP framework module written in Go
https://github.com/vaclovas2020/webimizer
Last synced: 4 months ago
JSON representation
Lightweight HTTP framework module written in Go
- Host: GitHub
- URL: https://github.com/vaclovas2020/webimizer
- Owner: vaclovas2020
- License: gpl-3.0
- Created: 2021-07-31T10:35:59.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2021-09-11T16:38:25.000Z (almost 4 years ago)
- Last Synced: 2025-01-10T10:34:47.540Z (5 months ago)
- Language: Go
- Homepage: https://pkg.go.dev/webimizer.dev/webimizer
- Size: 22.5 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# webimizer
Lightweight HTTP framework module written in Go
# Code example
```go
package mainimport (
"fmt"
"log"
"net/http"app "webimizer.dev/webimizer"
)func httpNotAllowFunc(rw http.ResponseWriter, r *http.Request) {
rw.WriteHeader(http.StatusBadRequest)
fmt.Fprint(rw, "Bad Request")
}func main() {
app.DefaultHTTPHeaders = [][]string{
{"x-content-type-options", "nosniff"},
{"x-frame-options", "SAMEORIGIN"},
{"x-xss-protection", "1; mode=block"},
} // define default headers
http.Handle("/", app.HttpHandlerStruct{
Handler: app.HttpHandler(func(rw http.ResponseWriter, r *http.Request) {
app.Get(rw, r, func(rw http.ResponseWriter, r *http.Request) {
fmt.Fprint(rw, "Hello from webimizer. HTTP GET method was used.")
})
app.Post(rw, r, func(rw http.ResponseWriter, r *http.Request) {
fmt.Fprint(rw, "Hello from webimizer. HTTP POST method was used.")
})
}), // app.HttpHandler call only if method is allowed
NotAllowHandler: app.HttpNotAllowHandler(httpNotAllowFunc), // app.HtttpNotAllowHandler call if method is not allowed
AllowedMethods: []string{"GET","POST"}, // define allowed methods
}.Build())
log.Fatal(http.ListenAndServe(":8080", nil)) // example server listen on port 8080
}
```