Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@mxro
Created April 17, 2021 03:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mxro/e8766e81cd13930aa56bc753b1cae8c1 to your computer and use it in GitHub Desktop.
Save mxro/e8766e81cd13930aa56bc753b1cae8c1 to your computer and use it in GitHub Desktop.
package main
import (
"os"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
)
func CreateServer() *gin.Engine {
r := gin.Default()
corsEnv := os.Getenv("CORS")
if corsEnv != "" {
config := cors.DefaultConfig()
config.AllowOrigins = []string{corsEnv}
r.Use(cors.New(config))
}
r.GET("/status", func(c *gin.Context) {
c.JSON(200, gin.H{
"status": "ok",
})
})
return r
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment