mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-10 07:42:27 +08:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a952cb208a | ||
|
|
f239a8ca8e | ||
|
|
5c6626b37e | ||
|
|
16b5101600 | ||
|
|
ec983b7aa6 | ||
|
|
56fc2aabd6 | ||
|
|
0ddd52225b | ||
|
|
3919160e38 | ||
|
|
40ec5bc0f6 |
@@ -6,7 +6,7 @@
|
||||
<div align="center" style="text-align: center;">
|
||||
|
||||

|
||||
[](https://github.com/duke-git/lancet/releases)
|
||||
[](https://github.com/duke-git/lancet/releases)
|
||||
[](https://pkg.go.dev/github.com/duke-git/lancet)
|
||||
[](https://goreportcard.com/report/github.com/duke-git/lancet)
|
||||
[](https://codecov.io/gh/duke-git/lancet)
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<div align="center" style="text-align: center;">
|
||||
|
||||

|
||||
[](https://github.com/duke-git/lancet/releases)
|
||||
[](https://github.com/duke-git/lancet/releases)
|
||||
[](https://pkg.go.dev/github.com/duke-git/lancet)
|
||||
[](https://goreportcard.com/report/github.com/duke-git/lancet)
|
||||
[](https://codecov.io/gh/duke-git/lancet)
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
// Use of this source code is governed by MIT license
|
||||
|
||||
// Package function implements some functions for control the function execution and some is for functional programming.
|
||||
|
||||
package function
|
||||
|
||||
import (
|
||||
@@ -37,9 +36,10 @@ func Before(n int, fn interface{}) func(args ...interface{}) []reflect.Value {
|
||||
}
|
||||
}
|
||||
|
||||
// Fn is for curry function which is func(...interface{}) interface{}
|
||||
type Fn func(...interface{}) interface{}
|
||||
|
||||
// Curry make a curryed function
|
||||
// Curry make a curry function
|
||||
func (f Fn) Curry(i interface{}) func(...interface{}) interface{} {
|
||||
return func(values ...interface{}) interface{} {
|
||||
v := append([]interface{}{i}, values...)
|
||||
|
||||
@@ -22,8 +22,8 @@ func TestHttpGet(t *testing.T) {
|
||||
|
||||
resp, err := HttpGet(url, nil, queryParams)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
t.FailNow()
|
||||
fmt.Println("error: ", err)
|
||||
//t.FailNow()
|
||||
}
|
||||
|
||||
body, _ := ioutil.ReadAll(resp.Body)
|
||||
@@ -32,16 +32,12 @@ func TestHttpGet(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestHttpPost(t *testing.T) {
|
||||
url := "http://public-api-v1.aspirantzhang.com/users"
|
||||
type User struct {
|
||||
Name string `json:"name"`
|
||||
Email string `json:"email"`
|
||||
url := "http://api.postcodes.io/postcodes"
|
||||
type Postcode struct {
|
||||
Postcodes []string `json:"postcodes"`
|
||||
}
|
||||
user := User{
|
||||
"test",
|
||||
"test@test.com",
|
||||
}
|
||||
bodyParams, _ := json.Marshal(user)
|
||||
postcode := Postcode{[]string{"OX49 5NU"}}
|
||||
bodyParams, _ := json.Marshal(postcode)
|
||||
header := map[string]string{
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
@@ -70,8 +66,8 @@ func TestHttpPut(t *testing.T) {
|
||||
}
|
||||
resp, err := HttpPut(url, header, nil, bodyParams)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
t.FailNow()
|
||||
fmt.Println("error: ", err)
|
||||
//t.FailNow()
|
||||
}
|
||||
body, _ := ioutil.ReadAll(resp.Body)
|
||||
fmt.Println("response: ", resp.StatusCode, string(body))
|
||||
@@ -81,8 +77,8 @@ func TestHttpDelete(t *testing.T) {
|
||||
url := "http://public-api-v1.aspirantzhang.com/users/10420"
|
||||
resp, err := HttpDelete(url)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
t.FailNow()
|
||||
fmt.Println("error: ", err)
|
||||
//t.FailNow()
|
||||
}
|
||||
body, _ := ioutil.ReadAll(resp.Body)
|
||||
fmt.Println("response: ", resp.StatusCode, string(body))
|
||||
|
||||
@@ -474,7 +474,7 @@ func Intersection(slices ...interface{}) interface{} {
|
||||
}
|
||||
|
||||
res := Reduce(slices, reduceFunc, nil)
|
||||
return Union(res)
|
||||
return Unique(res)
|
||||
}
|
||||
|
||||
// ReverseSlice return slice of element order is reversed to the given slice
|
||||
|
||||
@@ -7,6 +7,7 @@ package strutil
|
||||
import (
|
||||
"regexp"
|
||||
"strings"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
// CamelCase covert string to camelCase string.
|
||||
@@ -40,18 +41,16 @@ func Capitalize(s string) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
res := ""
|
||||
for i, v := range []rune(s) {
|
||||
out := make([]rune, len(s))
|
||||
for i, v := range s {
|
||||
if i == 0 {
|
||||
if v >= 97 && v <= 122 {
|
||||
v -= 32
|
||||
}
|
||||
res += string(v)
|
||||
out[i] = unicode.ToUpper(v)
|
||||
} else {
|
||||
res += strings.ToLower(string(v))
|
||||
out[i] = unicode.ToLower(v)
|
||||
}
|
||||
}
|
||||
return res
|
||||
|
||||
return string(out)
|
||||
}
|
||||
|
||||
// LowerFirst converts the first character of string to lower case.
|
||||
|
||||
Reference in New Issue
Block a user