1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-08 04:21:57 +00:00

add viper configuration example and minor improvements - read HISTORY.md

This commit is contained in:
Gerasimos (Makis) Maropoulos
2020-09-16 12:59:51 +03:00
parent f9e048e56b
commit 373b8993ad
20 changed files with 222 additions and 53 deletions

View File

@@ -4,6 +4,7 @@ import (
"bytes"
"net"
"strings"
"unsafe"
)
/* Based on:
@@ -13,13 +14,18 @@ https://github.com/kataras/iris/issues/1453
// IPRange is a structure that holds the start and end of a range of IP Addresses.
type IPRange struct {
Start net.IP `ini:"start" json:"start" yaml:"Start" toml:"Start"`
End net.IP `ini:"end" json:"end" yaml:"End" toml:"End"`
Start string `ini:"start" json:"start" yaml:"Start" toml:"Start"`
End string `ini:"end" json:"end" yaml:"End" toml:"End"`
}
func unsafeCompare(a []byte, b string) int {
bb := *(*[]byte)(unsafe.Pointer(&b))
return bytes.Compare(a, bb)
}
// IPInRange reports whether a given IP Address is within a range given.
func IPInRange(r IPRange, ipAddress net.IP) bool {
return bytes.Compare(ipAddress, r.Start) >= 0 && bytes.Compare(ipAddress, r.End) < 0
return unsafeCompare(ipAddress, r.Start) >= 0 && unsafeCompare(ipAddress, r.End) < 0
}
// IPIsPrivateSubnet reports whether this "ipAddress" is in a private subnet.