init
This commit is contained in:
commit
2f37d930ec
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
weather
|
||||
.idea
|
5
go.mod
Normal file
5
go.mod
Normal file
@ -0,0 +1,5 @@
|
||||
module weather
|
||||
|
||||
go 1.18
|
||||
|
||||
require github.com/briandowns/openweathermap v0.16.0
|
2
go.sum
Normal file
2
go.sum
Normal 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
33
main.go
Normal 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)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user