chore: add dev mode
This commit is contained in:
parent
b543d0c1f7
commit
50ff583672
2 changed files with 17 additions and 4 deletions
7
.envrc
7
.envrc
|
@ -1 +1,8 @@
|
|||
use flake
|
||||
|
||||
nix build nixpkgs#dbip-city-lite --no-link
|
||||
nix build nixpkgs#dbip-asn-lite --no-link
|
||||
|
||||
export IP_CHECKER_CITY_DB=$(nix eval nixpkgs#dbip-city-lite.mmdb --raw)
|
||||
export IP_CHECKER_ASN_DB=$(nix eval nixpkgs#dbip-asn-lite.mmdb --raw)
|
||||
export IP_CHECKER_MODE=dev
|
||||
|
|
14
main.go
14
main.go
|
@ -22,16 +22,18 @@ var (
|
|||
)
|
||||
|
||||
type ServerConfig struct {
|
||||
Listen string
|
||||
CityDB string
|
||||
ASNDB string
|
||||
CityDB string
|
||||
Listen string
|
||||
Mode string
|
||||
}
|
||||
|
||||
func main() {
|
||||
config = ServerConfig{
|
||||
Listen: getEnvOr("IP_CHECKER_LISTEN", ":8080"),
|
||||
CityDB: os.Getenv("IP_CHECKER_CITY_DB"),
|
||||
ASNDB: os.Getenv("IP_CHECKER_ASN_DB"),
|
||||
CityDB: os.Getenv("IP_CHECKER_CITY_DB"),
|
||||
Listen: getEnvOr("IP_CHECKER_LISTEN", ":8080"),
|
||||
Mode: os.Getenv("IP_CHECKER_MODE"),
|
||||
}
|
||||
|
||||
if config.CityDB != "" {
|
||||
|
@ -135,6 +137,10 @@ func getIPCountry(ip string) string {
|
|||
|
||||
func handleRequest(w http.ResponseWriter, r *http.Request) {
|
||||
sourceIP := func() string {
|
||||
if config.Mode == "dev" {
|
||||
return "223.5.5.5"
|
||||
}
|
||||
|
||||
if ip := r.Header.Get("X-Forwarded-For"); ip != "" {
|
||||
return strings.Split(ip, ",")[0]
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue