Moving structure definitions
This commit is contained in:
parent
bf5537668e
commit
3d85aff1a9
47
server.go
47
server.go
@ -36,30 +36,6 @@ import (
|
|||||||
var db *sql.DB
|
var db *sql.DB
|
||||||
|
|
||||||
func executeQuery(rw http.ResponseWriter, req *http.Request) {
|
func executeQuery(rw http.ResponseWriter, req *http.Request) {
|
||||||
type jsonFeatureMap map[string]float64
|
|
||||||
|
|
||||||
type jsonRange struct {
|
|
||||||
Max float64 `json:"max"`
|
|
||||||
Min float64 `json:"min"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type jsonGeo struct {
|
|
||||||
Latitude float64 `json:"latitude"`
|
|
||||||
Longitude float64 `json:"longitude"`
|
|
||||||
Valid bool `json:"valid"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type jsonRequest struct {
|
|
||||||
Features jsonFeatureMap `json:"features"`
|
|
||||||
Geo *jsonGeo `json:"geo"`
|
|
||||||
HintSteps int `json:"hintSteps"`
|
|
||||||
MaxResults int `json:"maxResults"`
|
|
||||||
MinScore float64 `json:"minScore"`
|
|
||||||
Profile jsonFeatureMap `json:"profile"`
|
|
||||||
Range jsonRange `json:"range"`
|
|
||||||
WalkingDist float64 `json:"walkingDist"`
|
|
||||||
}
|
|
||||||
|
|
||||||
var request jsonRequest
|
var request jsonRequest
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
||||||
http.Error(rw, err.Error(), http.StatusInternalServerError)
|
http.Error(rw, err.Error(), http.StatusInternalServerError)
|
||||||
@ -113,11 +89,6 @@ func executeQuery(rw http.ResponseWriter, req *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getCategories(rw http.ResponseWriter, req *http.Request) {
|
func getCategories(rw http.ResponseWriter, req *http.Request) {
|
||||||
type jsonCategory struct {
|
|
||||||
Description string `json:"description"`
|
|
||||||
Id int `json:"id"`
|
|
||||||
}
|
|
||||||
|
|
||||||
rows, err := db.Query("SELECT description, id FROM categories")
|
rows, err := db.Query("SELECT description, id FROM categories")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
@ -152,16 +123,6 @@ func getCategories(rw http.ResponseWriter, req *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func addCategory(rw http.ResponseWriter, req *http.Request) {
|
func addCategory(rw http.ResponseWriter, req *http.Request) {
|
||||||
type jsonAddCategoryRequest struct {
|
|
||||||
Description string `json:"description"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type jsonAddCategoryResponse struct {
|
|
||||||
Description string `json:"description"`
|
|
||||||
Id int `json:"id"`
|
|
||||||
Success bool `json:"success"`
|
|
||||||
}
|
|
||||||
|
|
||||||
var request jsonAddCategoryRequest
|
var request jsonAddCategoryRequest
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
||||||
http.Error(rw, err.Error(), http.StatusInternalServerError)
|
http.Error(rw, err.Error(), http.StatusInternalServerError)
|
||||||
@ -200,14 +161,6 @@ func addCategory(rw http.ResponseWriter, req *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func removeCategory(rw http.ResponseWriter, req *http.Request) {
|
func removeCategory(rw http.ResponseWriter, req *http.Request) {
|
||||||
type jsonRemoveCategoryRequest struct {
|
|
||||||
Id int `json:"id"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type jsonRemoveCategoryResponse struct {
|
|
||||||
Success bool `json:"success"`
|
|
||||||
}
|
|
||||||
|
|
||||||
var request jsonRemoveCategoryRequest
|
var request jsonRemoveCategoryRequest
|
||||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
||||||
http.Error(rw, err.Error(), http.StatusInternalServerError)
|
http.Error(rw, err.Error(), http.StatusInternalServerError)
|
||||||
|
47
types.go
47
types.go
@ -22,6 +22,53 @@
|
|||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
type jsonFeatureMap map[string]float64
|
||||||
|
|
||||||
|
type jsonRange struct {
|
||||||
|
Max float64 `json:"max"`
|
||||||
|
Min float64 `json:"min"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type jsonGeo struct {
|
||||||
|
Latitude float64 `json:"latitude"`
|
||||||
|
Longitude float64 `json:"longitude"`
|
||||||
|
Valid bool `json:"valid"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type jsonRequest struct {
|
||||||
|
Features jsonFeatureMap `json:"features"`
|
||||||
|
Geo *jsonGeo `json:"geo"`
|
||||||
|
HintSteps int `json:"hintSteps"`
|
||||||
|
MaxResults int `json:"maxResults"`
|
||||||
|
MinScore float64 `json:"minScore"`
|
||||||
|
Profile jsonFeatureMap `json:"profile"`
|
||||||
|
Range jsonRange `json:"range"`
|
||||||
|
WalkingDist float64 `json:"walkingDist"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type jsonCategory struct {
|
||||||
|
Description string `json:"description"`
|
||||||
|
Id int `json:"id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type jsonAddCategoryRequest struct {
|
||||||
|
Description string `json:"description"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type jsonAddCategoryResponse struct {
|
||||||
|
Description string `json:"description"`
|
||||||
|
Id int `json:"id"`
|
||||||
|
Success bool `json:"success"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type jsonRemoveCategoryRequest struct {
|
||||||
|
Id int `json:"id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type jsonRemoveCategoryResponse struct {
|
||||||
|
Success bool `json:"success"`
|
||||||
|
}
|
||||||
|
|
||||||
type queryContext struct {
|
type queryContext struct {
|
||||||
geo geoContext
|
geo geoContext
|
||||||
latitude float64
|
latitude float64
|
||||||
|
Loading…
Reference in New Issue
Block a user