-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(web): logging if no domain is entered (#1038)
* fix(web): IPv4/6 cannot be enabled without domains Currently, if IPv4/6 is enabled but there is no domain, nothing happens. In this case, we should throw an error. * fix: replace errors with logs * fix: logging only if no domain is entered * feat: logging index
- Loading branch information
1 parent
ae0f47f
commit 9aee04b
Showing
4 changed files
with
94 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package util | ||
|
||
import ( | ||
"strconv" | ||
|
||
"golang.org/x/text/language" | ||
) | ||
|
||
// Ordinal returns the ordinal format of the given number. | ||
// | ||
// See also: https://github.com/dustin/go-humanize/blob/master/ordinals.go | ||
func Ordinal(x int, lang string) string { | ||
s := strconv.Itoa(x) | ||
|
||
// Chinese doesn't require an ordinal | ||
if lang == language.Chinese.String() { | ||
return s | ||
} | ||
|
||
suffix := "th" | ||
switch x % 10 { | ||
case 1: | ||
if x%100 != 11 { | ||
suffix = "st" | ||
} | ||
case 2: | ||
if x%100 != 12 { | ||
suffix = "nd" | ||
} | ||
case 3: | ||
if x%100 != 13 { | ||
suffix = "rd" | ||
} | ||
} | ||
return s + suffix | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package util | ||
|
||
import "testing" | ||
|
||
func TestOrdinal(t *testing.T) { | ||
lang := "en" | ||
|
||
tests := []struct { | ||
name string | ||
got string | ||
want string | ||
}{ | ||
{"0", Ordinal(0, lang), "0th"}, | ||
{"1", Ordinal(1, lang), "1st"}, | ||
{"2", Ordinal(2, lang), "2nd"}, | ||
{"3", Ordinal(3, lang), "3rd"}, | ||
{"4", Ordinal(4, lang), "4th"}, | ||
{"10", Ordinal(10, lang), "10th"}, | ||
{"11", Ordinal(11, lang), "11th"}, | ||
{"12", Ordinal(12, lang), "12th"}, | ||
{"13", Ordinal(13, lang), "13th"}, | ||
{"21", Ordinal(21, lang), "21st"}, | ||
{"32", Ordinal(32, lang), "32nd"}, | ||
{"43", Ordinal(43, lang), "43rd"}, | ||
{"101", Ordinal(101, lang), "101st"}, | ||
{"102", Ordinal(102, lang), "102nd"}, | ||
{"103", Ordinal(103, lang), "103rd"}, | ||
{"211", Ordinal(211, lang), "211th"}, | ||
{"212", Ordinal(212, lang), "212th"}, | ||
{"213", Ordinal(213, lang), "213th"}, | ||
} | ||
|
||
for _, tt := range tests { | ||
if tt.got != tt.want { | ||
t.Errorf("On %s, Expected %s, but got %s", tt.name, tt.want, tt.got) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters