area

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 4, 2020 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Copyright 2019-2020 Axetroy. All rights reserved. MIT license.

Copyright 2019-2020 Axetroy. All rights reserved. MIT license.

Copyright 2019-2020 Axetroy. All rights reserved. MIT license.

Copyright 2019-2020 Axetroy. All rights reserved. MIT license.

Index

Constants

This section is empty.

Variables

View Source
var GetArea = router.Handler(func(c router.Context) {
	var query query

	c.ResponseFunc(c.ShouldBindQuery(&query), func() schema.Response {
		if query.Flatten {
			return schema.Response{
				Status:  schema.StatusSuccess,
				Message: "",
				Data:    area.MapsFlatten,
			}
		} else if query.Simple {
			return schema.Response{
				Status:  schema.StatusSuccess,
				Message: "",
				Data:    area.MapsSimplified,
			}
		} else {
			return schema.Response{
				Status:  schema.StatusSuccess,
				Message: "",
				Data:    area.Maps,
			}
		}
	})
})
View Source
var GetChildren = router.Handler(func(c router.Context) {
	fullAreaCode := c.Param("code")

	target, err := area.LookUp(fullAreaCode)

	c.ResponseFunc(err, func() schema.Response {
		var result = make([]area.Location, 0)

		var resultMap map[string]string

		switch len(target.Code) {
		case 2:
			resultMap = area.CityMap
			break
		case 4:
			resultMap = area.AreaMap
			break
		case 6:
			resultMap = area.StreetMap
			break
		case 9:
			resultMap = nil
			break
		}

		if resultMap != nil {
			for code, name := range resultMap {
				if strings.HasPrefix(code, target.Code) {
					result = append(result, area.Location{
						Code: code,
						Name: name,
					})
				}
			}
		}

		sort.SliceStable(result, func(i, j int) bool { return result[i].Code < result[j].Code })

		return schema.Response{
			Status:  schema.StatusSuccess,
			Message: "",
			Data:    result,
		}
	})
})
View Source
var GetDetail = router.Handler(func(c router.Context) {
	fullAreaCode := c.Param("code")

	target, err := area.LookUp(fullAreaCode)

	c.ResponseFunc(err, func() schema.Response {
		target.Children = nil
		return schema.Response{
			Status:  schema.StatusSuccess,
			Message: "",
			Data:    target,
		}
	})
})
View Source
var GetProvinces = router.Handler(func(c router.Context) {
	c.ResponseFunc(nil, func() schema.Response {
		var result = make([]area.Location, 0)

		for code, name := range area.ProvinceMap {
			result = append(result, area.Location{
				Name: name,
				Code: code,
			})
		}

		sort.SliceStable(result, func(i, j int) bool { return result[i].Code < result[j].Code })

		return schema.Response{
			Status:  schema.StatusSuccess,
			Message: "",
			Data:    result,
		}
	})
})

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL