Skip to content

flannel-dev-lab/cyclops

Repository files navigation

Cyclops

Go Report Card Build Status Go Doc codecov

GitHub Logo1

Download

go get github.com/flannel-dev-lab/cyclops/v2

Features

  • Plug and Play Middleware support
  • Customized response messages

Table of contents

  1. Middleware
  2. Cookies
  3. Handling Inputs
  4. Handling HTTP Requests
  5. Handling Sessions
  6. Logging

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)
}

About

Minimal, lightweight web framework

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages