cyclops

package module
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 12, 2020 License: MIT Imports: 4 Imported by: 0

README

Cyclops

Go Report Card Build Status Go Doc codecov

GitHub Logo1

Features

  • Plug and Play Middleware support
  • Plug and Play Alerting support
  • Customized response messages

Table of contents

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

Usage

package main

import (
	"fmt"
	"github.com/flannel-dev-lab/cyclops"
	"github.com/flannel-dev-lab/cyclops/response"
	"github.com/flannel-dev-lab/cyclops/router"
	"github.com/flannel-dev-lab/cyclops/middleware"
	"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)
}

Credits

  • Router implementation is inspired and modified accordingly from vestigo

Documentation

Overview

cyclops is a minimal web framework

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Param added in v1.1.0

func Param(r *http.Request, name string) string

Param - Get a url parameter by name

func StartServer

func StartServer(address string, handler http.Handler)

StartServer starts a simple http server

func StartTLSServer added in v0.1.0

func StartTLSServer(address string, handler http.Handler, certFile, keyFile string)

StartTLSServer starts a TLS server with provided TLS cert and key files

Types

This section is empty.

Directories

Path Synopsis
Package alerts handles the alerting systems such as Sentry, etc Package sentry implements the Alert interface for Sentry alerting systems
Package alerts handles the alerting systems such as Sentry, etc Package sentry implements the Alert interface for Sentry alerting systems
Package cookie deals with set, get and deleting of HTTP Cookies
Package cookie deals with set, get and deleting of HTTP Cookies
input deals with getting the values from form and query parameters
input deals with getting the values from form and query parameters
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
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
requester package is used to perform basic http requests
requester package is used to perform basic http requests

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL