commit
1692342766
4 changed files with 42 additions and 0 deletions
@ -0,0 +1,5 @@
@@ -0,0 +1,5 @@
|
||||
module weather |
||||
|
||||
go 1.18 |
||||
|
||||
require github.com/briandowns/openweathermap v0.16.0 |
@ -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= |
@ -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…
Reference in new issue