cors

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2022 License: MIT Imports: 3 Imported by: 2

README

Minima

This is package is wrapper based on rs/cors package made for minima.


Geting Started

Install the package using go get github.com/gominima/cors and call it in your main function


package main

import (
	"github.com/gominima/cors"
	"github.com/gominima/minima"
)

func main() {
	app := minima.New()
	crs := cors.New()
	app.Get("/", func(res *minima.Response, req *minima.Request) {
		res.OK().Send("Hello World")
		res.CloseConn()
	})
	app.Use(crs.AllowAll())
	app.Listen(":3000")
}

Try curling the the localhost the result would be something like this


$ curl -D - -H 'Origin: http://abc.com' http://localhost:3000/
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Vary: Origin
Date: Wed, 09 Feb 2022 03:42:42 GMT
Content-Length: 11
Content-Type: text/plain; charset=utf-8

Custom Cors

Using your own custom cors config is as simple as it gets thanks to rs/cors


app := minima.New()
crs := cors.New()
c := crs.NewCors(cors.Options{
    AllowedOrigins: []string{"http://ur_url.com"},
    AllowCredentials: true,
    // Enable Debugging for testing, consider disabling in production
    Debug: true,
})
app.Use(c())

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New() *corsWrapper

* @info Creates a corsWrapper instance @return {corsWrapper}

Types

type Options

type Options = cors.Options

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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