├── app.yml ├── .gitignore ├── README.md └── blip └── blip.go /app.yml: -------------------------------------------------------------------------------- 1 | application: blip-r7 2 | version: 1 3 | runtime: go 4 | api_version: go1 5 | 6 | handlers: 7 | - url: /.* 8 | script: _go_app -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | *.exe 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Blip: Very Simple Geolocation 2 | ==== 3 | 4 | Blip is a very simple JSON based user information API, powered by Google App Engine. 5 | 6 | Just hit http://blip.runway7.net - it gives you Google's best guess about where you are in JSON. 7 | 8 | If like Blip but don't want to rely on the Runway 7 instance, feel free to deploy your own - just change the application name in `app.yml` and follow the instructions [here](https://developers.google.com/appengine/docs/go/gettingstarted/uploading). 9 | -------------------------------------------------------------------------------- /blip/blip.go: -------------------------------------------------------------------------------- 1 | package blip 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "net/http" 7 | "strings" 8 | ) 9 | 10 | func init() { 11 | http.HandleFunc("/", handler) 12 | } 13 | 14 | func handler(w http.ResponseWriter, r *http.Request) { 15 | w.Header().Add("Content-Type", "application/json") 16 | w.Header().Add("Access-Control-Allow-Origin", "*") 17 | 18 | latLon := r.Header.Get("X-AppEngine-CityLatLong") 19 | parts := strings.Split(latLon, ",") 20 | lat := strings.TrimSpace(parts[0]) 21 | lon := strings.TrimSpace(parts[1]) 22 | 23 | m := map[string]string{ 24 | "latLong": latLon, 25 | "city": r.Header.Get("X-AppEngine-City"), 26 | "region": r.Header.Get("X-AppEngine-Region"), 27 | "country": r.Header.Get("X-AppEngine-Country"), 28 | "lat": lat, 29 | "lon": lon, 30 | } 31 | 32 | js, err := json.Marshal(m) 33 | 34 | if err != nil { 35 | http.Error(w, err.Error(), http.StatusInternalServerError) 36 | return 37 | } 38 | 39 | fmt.Fprint(w, string(js)) 40 | 41 | } 42 | --------------------------------------------------------------------------------