Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mununki/go-cors
A module to help to set up CORS for Go API or web Server
https://github.com/mununki/go-cors
cors go golang
Last synced: 10 days ago
JSON representation
A module to help to set up CORS for Go API or web Server
- Host: GitHub
- URL: https://github.com/mununki/go-cors
- Owner: mununki
- Created: 2019-06-04T16:58:09.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-06-05T03:07:13.000Z (over 5 years ago)
- Last Synced: 2024-04-24T03:22:04.423Z (8 months ago)
- Topics: cors, go, golang
- Language: Go
- Size: 1.95 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Go-CORS
This is a module to handle CORS for Go web API or Web Server.
## Usage
```go
mux.Handle("/", goCors.Set(http.Handler))
```> NOTE : Be aware of setting CORS `*` for `dev` mode only, in case of `prod`, BE careful it will allow any requests from any origin.
## Example
```go
import (
"log"
"net/http"goCors "github.com/mattdamon108/go-cors"
)func main() {
mux := http.NewServeMux()
mux.Handle("/", goCors.Set(Index{}))s := &http.Server{
Addr: ":8080",
Handler: mux,
}log.Println("Listening to... port 8080")
if err := s.ListenAndServe(); err != nil {
panic(err)
}
}type Index struct{}
func (i Index) ServeHTTP(w http.ResponseWriter, r *http.Request) {
path := "This is CORS test on path: " + r.URL.Path
w.Write([]byte(path))
}
```# Next to do
- [ ] Add the whitelist