cors

package
v0.0.0-...-abf8f43 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

README

CORS

The CORS handler adds the necessary CORS headers to a response.

Usage

package main

import (
        "fmt"
        "log"
        "net/http"

        "github.com/cloudlena/adapters/cors"
)

// IndexHandler says what it loves.
func IndexHandler() http.Handler {
        return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
                fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:])
        })
}

func main() {
        corsMiddleware := cors.Handler(cors.Options{})
        http.Handle("/", corsMiddleware(IndexHandler()))
        log.Fatal(http.ListenAndServe(":8080", nil))
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Handler

func Handler(o Options) func(http.Handler) http.Handler

Handler adds CORS headers to the response.

Types

type Options

type Options struct {
	Origins     []string
	Methods     []string
	Headers     []string
	Credentials bool
}

Options configure a CORS handler.

Jump to

Keyboard shortcuts

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