Added list all nodes API for backend, with bazel build system.
This commit is contained in:
parent
c090dd60c6
commit
22855ebec2
|
@ -0,0 +1 @@
|
||||||
|
/bazel-*
|
|
@ -0,0 +1,24 @@
|
||||||
|
load("@bazel_gazelle//:def.bzl", "gazelle")
|
||||||
|
|
||||||
|
gazelle(name = "gazelle")
|
||||||
|
|
||||||
|
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
|
||||||
|
|
||||||
|
go_library(
|
||||||
|
name = "go_default_library",
|
||||||
|
srcs = ["main.go"],
|
||||||
|
importpath = "git.eve.moe/jackyyf/navigator",
|
||||||
|
visibility = ["//visibility:private"],
|
||||||
|
deps = [
|
||||||
|
"//ipgeo:go_default_library",
|
||||||
|
"//mapping:go_default_library",
|
||||||
|
"@com_github_ipipdotnet_ipdb_go//:go_default_library",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
go_binary(
|
||||||
|
name = "navigator",
|
||||||
|
pure = "on",
|
||||||
|
embed = [":go_default_library"],
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
)
|
|
@ -0,0 +1,43 @@
|
||||||
|
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
|
||||||
|
|
||||||
|
http_archive(
|
||||||
|
name = "io_bazel_rules_go",
|
||||||
|
urls = [
|
||||||
|
"https://storage.googleapis.com/bazel-mirror/github.com/bazelbuild/rules_go/releases/download/v0.20.3/rules_go-v0.20.3.tar.gz",
|
||||||
|
"https://github.com/bazelbuild/rules_go/releases/download/v0.20.3/rules_go-v0.20.3.tar.gz",
|
||||||
|
],
|
||||||
|
sha256 = "e88471aea3a3a4f19ec1310a55ba94772d087e9ce46e41ae38ecebe17935de7b",
|
||||||
|
)
|
||||||
|
|
||||||
|
http_archive(
|
||||||
|
name = "bazel_gazelle",
|
||||||
|
urls = [
|
||||||
|
"https://storage.googleapis.com/bazel-mirror/github.com/bazelbuild/bazel-gazelle/releases/download/v0.19.1/bazel-gazelle-v0.19.1.tar.gz",
|
||||||
|
"https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.19.1/bazel-gazelle-v0.19.1.tar.gz",
|
||||||
|
],
|
||||||
|
sha256 = "86c6d481b3f7aedc1d60c1c211c6f76da282ae197c3b3160f54bd3a8f847896f",
|
||||||
|
)
|
||||||
|
|
||||||
|
load("@io_bazel_rules_go//go:deps.bzl", "go_rules_dependencies", "go_register_toolchains")
|
||||||
|
|
||||||
|
go_rules_dependencies()
|
||||||
|
|
||||||
|
go_register_toolchains()
|
||||||
|
|
||||||
|
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies", "go_repository")
|
||||||
|
|
||||||
|
gazelle_dependencies()
|
||||||
|
|
||||||
|
go_repository(
|
||||||
|
name = "com_github_ipipdotnet_ipdb_go",
|
||||||
|
importpath = "github.com/ipipdotnet/ipdb-go",
|
||||||
|
sum = "h1:Afa0qx/SgRevzIK8Qg1TevuD5M28kFLWbzPvU+GQJ08=",
|
||||||
|
version = "v1.2.0",
|
||||||
|
)
|
||||||
|
|
||||||
|
go_repository(
|
||||||
|
name = "net_starlark_go",
|
||||||
|
importpath = "go.starlark.net",
|
||||||
|
sum = "h1:ZP11CRSzO9uOTTOVkH6yodtI3kSY69vUID8lx8B0M3s=",
|
||||||
|
version = "v0.0.0-20191113183327-aaf7be003892",
|
||||||
|
)
|
|
@ -0,0 +1,14 @@
|
||||||
|
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||||
|
|
||||||
|
go_library(
|
||||||
|
name = "go_default_library",
|
||||||
|
srcs = ["ipdb.go"],
|
||||||
|
importpath = "git.eve.moe/jackyyf/navigator/ipgeo",
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
deps = [
|
||||||
|
"//mapping/elf:go_default_library",
|
||||||
|
"@com_github_ipipdotnet_ipdb_go//:go_default_library",
|
||||||
|
"@net_starlark_go//starlark:go_default_library",
|
||||||
|
"@net_starlark_go//starlarkstruct:go_default_library",
|
||||||
|
],
|
||||||
|
)
|
21
main.go
21
main.go
|
@ -151,6 +151,27 @@ func main() {
|
||||||
log.Printf("%s => %s\n", ip, server)
|
log.Printf("%s => %s\n", ip, server)
|
||||||
fmt.Fprint(resp, server)
|
fmt.Fprint(resp, server)
|
||||||
})
|
})
|
||||||
|
http.HandleFunc("/getNodes", func(resp http.ResponseWriter, req *http.Request) {
|
||||||
|
ip := req.FormValue("ip")
|
||||||
|
if net.ParseIP(ip).To4() == nil {
|
||||||
|
responseWithError(resp, http.StatusBadRequest, errIPv4Only)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
nodes := mapping.GetNodes()
|
||||||
|
if nodes == nil {
|
||||||
|
responseWithJsonError(resp, http.StatusInternalServerError, "Unable to get nodes")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
suffix := mapping.GetSuffix(ip)
|
||||||
|
resp.Header().Set("Content-Type", "application/json")
|
||||||
|
resp.WriteHeader(http.StatusOK)
|
||||||
|
jsonEncoder := json.NewEncoder(resp)
|
||||||
|
ret := make([]string, 0, len(nodes))
|
||||||
|
for _, node := range nodes {
|
||||||
|
ret = append(ret, node+suffix)
|
||||||
|
}
|
||||||
|
jsonEncoder.Encode(ret)
|
||||||
|
})
|
||||||
clientApi := http.NewServeMux()
|
clientApi := http.NewServeMux()
|
||||||
http.Handle("/client/", http.StripPrefix("/client", clientApi))
|
http.Handle("/client/", http.StripPrefix("/client", clientApi))
|
||||||
clientV1Api := http.NewServeMux()
|
clientV1Api := http.NewServeMux()
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||||
|
|
||||||
|
go_library(
|
||||||
|
name = "go_default_library",
|
||||||
|
srcs = ["map.go"],
|
||||||
|
importpath = "git.eve.moe/jackyyf/navigator/mapping",
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
deps = ["//mapping/elf:go_default_library"],
|
||||||
|
)
|
|
@ -0,0 +1,9 @@
|
||||||
|
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||||
|
|
||||||
|
go_library(
|
||||||
|
name = "go_default_library",
|
||||||
|
srcs = ["core.go"],
|
||||||
|
importpath = "git.eve.moe/jackyyf/navigator/mapping/elf",
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
deps = ["@net_starlark_go//starlark:go_default_library"],
|
||||||
|
)
|
Loading…
Reference in New Issue