This commit is contained in:
Evan Burkey 2022-03-10 09:23:32 -08:00
commit 2f37d930ec
4 changed files with 42 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
weather
.idea

5
go.mod Normal file
View File

@ -0,0 +1,5 @@
module weather
go 1.18
require github.com/briandowns/openweathermap v0.16.0

2
go.sum Normal file
View File

@ -0,0 +1,2 @@
github.com/briandowns/openweathermap v0.16.0 h1:js8THhUE4nVYbpedSCs0E5vxYzxkkOLtxrOFh9xed8c=
github.com/briandowns/openweathermap v0.16.0/go.mod h1:0GLnknqicWxXnGi1IqoOaZIw+kIe5hkt+YM5WY3j8+0=

33
main.go Normal file
View File

@ -0,0 +1,33 @@
package main
import (
"fmt"
"log"
"os"
"strconv"
owm "github.com/briandowns/openweathermap"
)
var apiKey string
func init() {
apiKey = os.Getenv("OWM_API_KEY")
if apiKey == "" {
log.Fatal("No API key")
}
}
func main() {
w, err := owm.NewCurrent("F", "en", apiKey)
if err != nil {
log.Fatalln(err)
}
err = w.CurrentByZip(97351, "us")
if err != nil {
log.Fatalln(err)
}
out := w.Weather[0].Description + " " + strconv.Itoa(int(w.Main.Temp)) + " °F"
fmt.Println(out)
}