area

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2020 License: MIT Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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
		case 4:
			resultMap = area.AreaMap
		case 6:
			resultMap = area.StreetMap
		case 9:
			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