modulepackage
2.1.0
Repository: https://github.com/flannel-dev-lab/cyclops.git
Documentation: pkg.go.dev
# README
Cyclops
Download
go get github.com/flannel-dev-lab/cyclops/v2
Features
- Plug and Play Middleware support
- Customized response messages
Table of contents
Usage
package main
import (
"fmt"
"github.com/flannel-dev-lab/cyclops/v2"
"github.com/flannel-dev-lab/cyclops/v2/middleware"
"github.com/flannel-dev-lab/cyclops/v2/response"
"github.com/flannel-dev-lab/cyclops/v2/router"
"net/http"
)
func main() {
routerObj := router.New(false, nil, nil)
routerObj.Get("/hello", middleware.NewChain().Then(Hello))
routerObj.Post("/bye", Bye)
// Named parameters can be used as
routerObj.Get("/users/:name", middleware.NewChain().Then(PathParam))
// static can be registered as
routerObj.RegisterStatic("{PATH TO STATIC DIRECTORY}", "/static/")
cyclops.StartServer(":8080", routerObj)
}
func PathParam(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hi %s", cyclops.Param(r, "name"))
response.SuccessResponse(200, w, nil)
}
func Hello(w http.ResponseWriter, r *http.Request) {
response.SuccessResponse(200, w, nil)
}
func Bye(w http.ResponseWriter, r *http.Request) {
response.SuccessResponse(200, w, nil)
}
# Packages
Package cookie deals with set, get and deleting of HTTP Cookies.
input deals with getting the values from form and query parameters.
Package logger contains the functions related to logging.
middleware package includes different middleware available by default with cyclops, cyclops is made in such a way that it is easy for developers to plug custom middleware as well, the only thing that the developer need to do is write a middleware that takes in a http.Handler and returns a http.Handler, once the middleware is complete pass it to NewChain method to start using it.
No description provided by the author
No description provided by the author
No description provided by the author
# Functions
Param - Get a url parameter by name.
StartServer starts a simple http server.
StartTLSServer starts a TLS server with provided TLS cert and key files.