-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(fxcore): Updated core http server metrics configurations
- Loading branch information
Showing
3 changed files
with
46 additions
and
4 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,16 @@ | ||
package fxcore | ||
|
||
import "strings" | ||
|
||
// Sanitize transforms a given string to not contain spaces or dashes, and to be in lower case. | ||
func Sanitize(str string) string { | ||
san := strings.ReplaceAll(str, " ", "_") | ||
san = strings.ReplaceAll(san, "-", "_") | ||
|
||
return strings.ToLower(san) | ||
} | ||
|
||
// Split trims and splits a provided string by comma. | ||
func Split(str string) []string { | ||
return strings.Split(strings.ReplaceAll(str, " ", ""), ",") | ||
} |
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,27 @@ | ||
package fxcore_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/ankorstore/yokai/fxcore" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestSanitize(t *testing.T) { | ||
t.Parallel() | ||
|
||
assert.Equal(t, "foo_bar", fxcore.Sanitize("foo-bar")) | ||
assert.Equal(t, "foo_bar", fxcore.Sanitize("foo bar")) | ||
assert.Equal(t, "foo_bar", fxcore.Sanitize("Foo-Bar")) | ||
assert.Equal(t, "foo_bar", fxcore.Sanitize("Foo Bar")) | ||
} | ||
|
||
func TestSplit(t *testing.T) { | ||
t.Parallel() | ||
|
||
assert.Equal(t, []string{"1", "2", "3"}, fxcore.Split("1,2,3")) | ||
assert.Equal(t, []string{"1", "2", "3"}, fxcore.Split(" 1,2,3")) | ||
assert.Equal(t, []string{"1", "2", "3"}, fxcore.Split("1,2,3 ")) | ||
assert.Equal(t, []string{"1", "2", "3"}, fxcore.Split("1, 2, 3")) | ||
assert.Equal(t, []string{"1", "2", "3"}, fxcore.Split(" 1, 2, 3 ")) | ||
} |