Skip to content

Commit

Permalink
add iscodeXXX
Browse files Browse the repository at this point in the history
  • Loading branch information
wenzuochao authored and peze committed Feb 27, 2020
1 parent 73f814e commit 5c6cc8a
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
16 changes: 16 additions & 0 deletions golang/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,19 @@ func GetUserAgent(userAgent string) string {
}
return defaultUserAgent
}

func Is2xx(code int) bool {
return code >= 200 && code < 300
}

func Is3xx(code int) bool {
return code >= 300 && code < 400
}

func Is4xx(code int) bool {
return code >= 400 && code < 500
}

func Is5xx(code int) bool {
return code >= 500 && code < 600
}
20 changes: 20 additions & 0 deletions golang/service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,23 @@ func Test_UserAgent(t *testing.T) {
utils.AssertEqual(t, len(GetUserAgent("ccp")), 65)
utils.AssertContains(t, GetUserAgent("ccp"), " ccp")
}

func Test_Is2xx(t *testing.T) {
utils.AssertEqual(t, Is2xx(200), true)
utils.AssertEqual(t, Is2xx(300), false)
}

func Test_Is3xx(t *testing.T) {
utils.AssertEqual(t, Is3xx(300), true)
utils.AssertEqual(t, Is3xx(400), false)
}

func Test_Is4xx(t *testing.T) {
utils.AssertEqual(t, Is4xx(400), true)
utils.AssertEqual(t, Is4xx(500), false)
}

func Test_Is5xx(t *testing.T) {
utils.AssertEqual(t, Is5xx(500), true)
utils.AssertEqual(t, Is5xx(600), false)
}
25 changes: 25 additions & 0 deletions main.tea
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,28 @@ static function assertAsMap(value: any): map[string]any;
* @return the string value
*/
static function getUserAgent(userAgent: string): string;

/**
* If the code between 200 and 300, return true, or return false
* @return boolean
*/
static function is2xx(code: number): boolean;

/**
* If the code between 300 and 400, return true, or return false
* @return boolean
*/
static function is3xx(code: number): boolean;

/**
* If the code between 400 and 500, return true, or return false
* @return boolean
*/
static function is4xx(code: number): boolean;

/**
* If the code between 500 and 600, return true, or return false
* @return boolean
*/
static function is5xx(code: number): boolean;

0 comments on commit 5c6cc8a

Please sign in to comment.