Skip to content

Instantly share code, notes, and snippets.

@nkreiger
Created June 22, 2021 02:09
Show Gist options
  • Save nkreiger/3c3d4f277e35747824770f12be098aad to your computer and use it in GitHub Desktop.
Save nkreiger/3c3d4f277e35747824770f12be098aad to your computer and use it in GitHub Desktop.
go-urls basic
// main.go
package main
import (
"app/connections"
"log"
)
func main() {
log.Println(connections.Connections.WeatherAPI)
}
// connections -> init.go
package connections
import (
"gopkg.in/yaml.v2"
"io/ioutil"
"log"
)
type config struct {
WeatherAPI weatherapi `yaml:"weatherapi"`
}
var Connections config
func init() {
file, err := ioutil.ReadFile("./config.yaml")
if err != nil {
log.Fatal(err)
}
err = yaml.Unmarshal(file, &Connections)
if err != nil {
log.Fatal(err)
}
}
// connections -> weatherapi.go
package connections
type weatherapi struct {
Scheme string `yaml:"scheme"`
Host string `yaml:"host"`
Endpoints weatherEndpoints `yaml:"endpoints"`
}
type weatherEndpoints struct {
Forecast endpoint `yaml:"forecast"`
Sports endpoint `yaml:"sports"`
}
// connections -> endpoints.go
package connections
type endpoint struct {
Path string `yaml:"path"`
Method string `yaml:"method"`
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment