Skip to content

Instantly share code, notes, and snippets.

@EtienneR
Created November 20, 2016 14:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save EtienneR/df0df0490758ea10d8f1c25b59885f7e to your computer and use it in GitHub Desktop.
Save EtienneR/df0df0490758ea10d8f1c25b59885f7e to your computer and use it in GitHub Desktop.
'title': 'This is my go blog'
'email': 'go@email.com'
'tags': [go, golang, yaml, json]
package main
import (
"log"
"io/ioutil"
"gopkg.in/gin-gonic/gin.v1"
"gopkg.in/yaml.v2"
)
type Config struct {
Title string `json:"title"`
Email string `json:"email"`
Tags []string `json:"tags"`
}
func main() {
r := gin.Default()
r.GET("", func(c *gin.Context) {
data, err := ioutil.ReadFile("config.yml")
if err != nil {
log.Fatalf("error: %v", err)
}
var config Config
err = yaml.Unmarshal([]byte(data), &config)
if err != nil {
log.Fatalf("error: %v", err)
}
result := Config{
Title: config.Title,
Email: config.Email,
Tags: config.Tags,
}
c.JSON(200, result)
})
r.Run(":3000")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment