cors

command
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2020 License: BSD-3-Clause Imports: 4 Imported by: 0

README

Example of CORS in FastHttpRouter

Shows how CORS can be enabled and used!

CORS example
package main

import (
  "fmt"
  "log"

  "github.com/georgecookeIW/fasthttprouter"
  "github.com/valyala/fasthttp"
)

// Index is the index handler
func HelloWorld(ctx *fasthttp.RequestCtx) {
  fmt.Fprint(ctx, "Hello World!\n")
}

// Hello is the Hello handler
func Echo(ctx *fasthttp.RequestCtx) {
  fmt.Fprintf(ctx, "hello, %s!\n", ctx.UserValue("name"))
}

func main() {
  router := fasthttprouter.New()

  router.HandleOPTIONS = true
  router.HandleCORS.Handle = true
  router.HandleCORS.AllowOrigin = "*.foo.com"
  router.HandleCORS.AllowMethods = []string{"GET"}
  
  router.GET("/", HelloWorld)
  router.GET("/echo/:name", Echo)

  log.Fatal(fasthttp.ListenAndServe(":8080", router.Handler))
}

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

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