Created
June 22, 2021 02:09
-
-
Save nkreiger/3c3d4f277e35747824770f12be098aad to your computer and use it in GitHub Desktop.
go-urls basic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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