Browse Source

init

master
Evan Burkey 11 months ago
commit
1692342766
  1. 2
      .gitignore
  2. 5
      go.mod
  3. 2
      go.sum
  4. 33
      main.go

2
.gitignore vendored

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

5
go.mod

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

2
go.sum

@ -0,0 +1,2 @@ @@ -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

@ -0,0 +1,33 @@ @@ -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…
Cancel
Save