forked from GoesToEleven/GolangTraining
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hello.go
executable file
·42 lines (35 loc) · 832 Bytes
/
hello.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"github.com/rwcarlsen/goexif/exif"
"html/template"
"log"
"net/http"
"os"
)
const GoogleAPIKey = "AIzaSyDpMNCWNz2UENVGQOS6zMFvtLsXn0zMBf4"
var tpls *template.Template
func init() {
var err error
tpls, err = template.ParseFiles("assets/templates/index.gohtml")
if err != nil {
log.Fatalln(err)
}
http.HandleFunc("/", handleIndex)
}
func handleIndex(res http.ResponseWriter, req *http.Request) {
src, _ := os.Open("assets/img/IMG_20150714_191905.jpg")
defer src.Close()
x, _ := exif.Decode(src)
lat, lon, _ := x.LatLong()
var model struct {
Latitude, Longitude float64
Key string
}
model.Latitude = lat
model.Longitude = lon
model.Key = GoogleAPIKey
err := tpls.ExecuteTemplate(res, "index.gohtml", model)
if err != nil {
http.Error(res, err.Error(), 500)
}
}