Add hideToken func.

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu 2016-05-16 20:36:56 +08:00
parent 3ebcbbed72
commit 537605a86c
2 changed files with 20 additions and 1 deletions

View File

@ -7,7 +7,7 @@ import (
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"os" "os"
// "time" "strings"
) )
var ( var (
@ -181,6 +181,20 @@ func typeForPlatForm(platform int) string {
} }
} }
func hideToken(token string, starLen int) string {
if len(token) == 0 {
return ""
}
start := token[len(token)-starLen:]
end := token[0:starLen]
result := strings.Replace(token, start, strings.Repeat("*", starLen), -1)
result = strings.Replace(result, end, strings.Repeat("*", starLen), -1)
return result
}
// LogPush record user push request and server response. // LogPush record user push request and server response.
func LogPush(status, token string, req PushNotification, errPush error) { func LogPush(status, token string, req PushNotification, errPush error) {
var plat, platColor, output string var plat, platColor, output string

View File

@ -88,3 +88,8 @@ func TestPlatFormColor(t *testing.T) {
assert.Equal(t, yellow, colorForPlatForm(PlatFormAndroid)) assert.Equal(t, yellow, colorForPlatForm(PlatFormAndroid))
assert.Equal(t, reset, colorForPlatForm(1000000)) assert.Equal(t, reset, colorForPlatForm(1000000))
} }
func TestHideToken(t *testing.T) {
assert.Equal(t, "", hideToken("", 2))
assert.Equal(t, "**345678**", hideToken("1234567890", 2))
}