mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-23 13:52:26 +08:00
Compare commits
15 Commits
v2.1.4
...
4eeeabb227
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4eeeabb227 | ||
|
|
b3437fdddf | ||
|
|
312dcab369 | ||
|
|
0cb89f4f46 | ||
|
|
a2dec87995 | ||
|
|
9094cb29bf | ||
|
|
ddb992ad2f | ||
|
|
24f18aaaec | ||
|
|
36169874e5 | ||
|
|
23aeb6ac99 | ||
|
|
a1984f0a59 | ||
|
|
c95db23d2c | ||
|
|
fbf251d805 | ||
|
|
337f08a04b | ||
|
|
c6a7371049 |
@@ -37,7 +37,7 @@ go get github.com/duke-git/lancet/v2 // will install latest version of v2.x.x
|
|||||||
|
|
||||||
2. <b>For users who use version below go1.18, you should install v1.x.x. now latest v1 is v1.3.1. </b>
|
2. <b>For users who use version below go1.18, you should install v1.x.x. now latest v1 is v1.3.1. </b>
|
||||||
```go
|
```go
|
||||||
go get github.com/duke-git/lancet@v1.3.0 // below go1.18, install latest version of v1.x.x
|
go get github.com/duke-git/lancet@v1.3.1 // below go1.18, install latest version of v1.x.x
|
||||||
```
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ go get github.com/duke-git/lancet/v2 //安装v2最新版本v2.x.x
|
|||||||
|
|
||||||
2. <b>使用go1.18以下版本的用户,必须安装v1.x.x。目前最新的v1版本是v1.3.1。</b>
|
2. <b>使用go1.18以下版本的用户,必须安装v1.x.x。目前最新的v1版本是v1.3.1。</b>
|
||||||
```go
|
```go
|
||||||
go get github.com/duke-git/lancet@v1.3.0 // 使用go1.18以下版本, 必须安装v1.x.x版本
|
go get github.com/duke-git/lancet@v1.3.1 // 使用go1.18以下版本, 必须安装v1.x.x版本
|
||||||
```
|
```
|
||||||
|
|
||||||
## 用法
|
## 用法
|
||||||
@@ -489,7 +489,6 @@ import "github.com/duke-git/lancet/v2/validator"
|
|||||||
- [IsUrl](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#IsUrl)
|
- [IsUrl](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#IsUrl)
|
||||||
- [IsWeakPassword](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#IsWeakPassword)
|
- [IsWeakPassword](https://github.com/duke-git/lancet/blob/main/docs/validator_zh-CN.md#IsWeakPassword)
|
||||||
|
|
||||||
validator.md#IsWeakPassword)
|
|
||||||
### 19. xerror包实现一些错误处理函数
|
### 19. xerror包实现一些错误处理函数
|
||||||
|
|
||||||
```go
|
```go
|
||||||
|
|||||||
@@ -65,11 +65,15 @@ func ShellSort[T any](slice []T, comparator lancetconstraints.Comparator) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// QuickSort quick sorting for slice, lowIndex is 0 and highIndex is len(slice)-1
|
// QuickSort quick sorting for slice, lowIndex is 0 and highIndex is len(slice)-1
|
||||||
func QuickSort[T any](slice []T, lowIndex, highIndex int, comparator lancetconstraints.Comparator) {
|
func QuickSort[T any](slice []T, comparator lancetconstraints.Comparator) {
|
||||||
|
quickSort(slice, 0, len(slice)-1, comparator)
|
||||||
|
}
|
||||||
|
|
||||||
|
func quickSort[T any](slice []T, lowIndex, highIndex int, comparator lancetconstraints.Comparator) {
|
||||||
if lowIndex < highIndex {
|
if lowIndex < highIndex {
|
||||||
p := partition(slice, lowIndex, highIndex, comparator)
|
p := partition(slice, lowIndex, highIndex, comparator)
|
||||||
QuickSort(slice, lowIndex, p-1, comparator)
|
quickSort(slice, lowIndex, p-1, comparator)
|
||||||
QuickSort(slice, p+1, highIndex, comparator)
|
quickSort(slice, p+1, highIndex, comparator)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,14 +30,6 @@ func (pc *peopleAgeComparator) Compare(v1 any, v2 any) int {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// var peoples = []people{
|
|
||||||
// {Name: "a", Age: 20},
|
|
||||||
// {Name: "b", Age: 10},
|
|
||||||
// {Name: "c", Age: 17},
|
|
||||||
// {Name: "d", Age: 8},
|
|
||||||
// {Name: "e", Age: 28},
|
|
||||||
// }
|
|
||||||
|
|
||||||
type intComparator struct{}
|
type intComparator struct{}
|
||||||
|
|
||||||
func (c *intComparator) Compare(v1 any, v2 any) int {
|
func (c *intComparator) Compare(v1 any, v2 any) int {
|
||||||
@@ -53,8 +45,6 @@ func (c *intComparator) Compare(v1 any, v2 any) int {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// var intSlice = []int{2, 1, 5, 3, 6, 4}
|
|
||||||
|
|
||||||
func TestBubbleSortForStructSlice(t *testing.T) {
|
func TestBubbleSortForStructSlice(t *testing.T) {
|
||||||
asssert := internal.NewAssert(t, "TestBubbleSortForStructSlice")
|
asssert := internal.NewAssert(t, "TestBubbleSortForStructSlice")
|
||||||
|
|
||||||
@@ -151,7 +141,7 @@ func TestQuickSort(t *testing.T) {
|
|||||||
{Name: "e", Age: 28},
|
{Name: "e", Age: 28},
|
||||||
}
|
}
|
||||||
comparator := &peopleAgeComparator{}
|
comparator := &peopleAgeComparator{}
|
||||||
QuickSort(peoples, 0, len(peoples)-1, comparator)
|
QuickSort(peoples, comparator)
|
||||||
|
|
||||||
expected := "[{d 8} {b 10} {c 17} {a 20} {e 28}]"
|
expected := "[{d 8} {b 10} {c 17} {a 20} {e 28}]"
|
||||||
actual := fmt.Sprintf("%v", peoples)
|
actual := fmt.Sprintf("%v", peoples)
|
||||||
136
datastructure/hashmap/hashmap.go
Normal file
136
datastructure/hashmap/hashmap.go
Normal file
@@ -0,0 +1,136 @@
|
|||||||
|
// Copyright 2021 dudaodong@gmail.com. All rights reserved.
|
||||||
|
// Use of this source code is governed by MIT license
|
||||||
|
|
||||||
|
// Package datastructure implements some data structure. eg. list, linklist, stack, queue, tree, graph.
|
||||||
|
package datastructure
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"hash/fnv"
|
||||||
|
)
|
||||||
|
|
||||||
|
var defaultMapCapacity uint64 = 1 << 10
|
||||||
|
|
||||||
|
type mapNode struct {
|
||||||
|
key any
|
||||||
|
value any
|
||||||
|
next *mapNode
|
||||||
|
}
|
||||||
|
|
||||||
|
//HashMap implements a hash map
|
||||||
|
type HashMap struct {
|
||||||
|
capacity uint64
|
||||||
|
size uint64
|
||||||
|
table []*mapNode
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewHashMap return a HashMap instance
|
||||||
|
func NewHashMap() *HashMap {
|
||||||
|
return &HashMap{
|
||||||
|
capacity: defaultMapCapacity,
|
||||||
|
table: make([]*mapNode, defaultMapCapacity),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewHashMapWithCapacity return a HashMap instance with given size and capacity
|
||||||
|
func NewHashMapWithCapacity(size, capacity uint64) *HashMap {
|
||||||
|
return &HashMap{
|
||||||
|
size: size,
|
||||||
|
capacity: capacity,
|
||||||
|
table: make([]*mapNode, capacity),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get return the value of given key in hashmap
|
||||||
|
func (hm *HashMap) Get(key any) any {
|
||||||
|
hashValue := hm.hash(key)
|
||||||
|
node := hm.table[hashValue]
|
||||||
|
if node != nil {
|
||||||
|
return node.value
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Put new key value in hashmap
|
||||||
|
func (hm *HashMap) Put(key any, value any) any {
|
||||||
|
return hm.putValue(hm.hash(key), key, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (hm *HashMap) putValue(hash uint64, key, value any) any {
|
||||||
|
if hm.capacity == 0 {
|
||||||
|
hm.capacity = defaultMapCapacity
|
||||||
|
hm.table = make([]*mapNode, defaultMapCapacity)
|
||||||
|
}
|
||||||
|
|
||||||
|
node := hm.table[hash]
|
||||||
|
if node == nil {
|
||||||
|
hm.table[hash] = newMapNode(key, value)
|
||||||
|
} else if node.key == key {
|
||||||
|
hm.table[hash] = newMapNodeWithNext(key, value, node)
|
||||||
|
return value
|
||||||
|
} else {
|
||||||
|
hm.resize()
|
||||||
|
return hm.putValue(hash, value, value)
|
||||||
|
}
|
||||||
|
hm.size++
|
||||||
|
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete item by given key in hashmap
|
||||||
|
func (hm *HashMap) Delete(key any) {
|
||||||
|
hash := hm.hash(key)
|
||||||
|
node := hm.table[hash]
|
||||||
|
if node == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
hm.table = append(hm.table[:hash], hm.table[hash+1:]...)
|
||||||
|
hm.size--
|
||||||
|
}
|
||||||
|
|
||||||
|
// Contains checks if given key is in hashmap or not
|
||||||
|
func (hm *HashMap) Contains(key any) bool {
|
||||||
|
node := hm.table[hm.hash(key)]
|
||||||
|
return node != nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (hm *HashMap) resize() {
|
||||||
|
hm.capacity <<= 1
|
||||||
|
|
||||||
|
tempTable := hm.table
|
||||||
|
|
||||||
|
for i := 0; i < len(tempTable); i++ {
|
||||||
|
node := tempTable[i]
|
||||||
|
if node == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
hm.table[hm.hash(node.key)] = node
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (hm *HashMap) hash(key any) uint64 {
|
||||||
|
h := fnv.New64a()
|
||||||
|
_, _ = h.Write([]byte(fmt.Sprintf("%v", key)))
|
||||||
|
|
||||||
|
hashValue := h.Sum64()
|
||||||
|
|
||||||
|
return (hm.capacity - 1) & (hashValue ^ (hashValue >> 16))
|
||||||
|
}
|
||||||
|
|
||||||
|
func newMapNode(key, value any) *mapNode {
|
||||||
|
return &mapNode{
|
||||||
|
key: key,
|
||||||
|
value: value,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func newMapNodeWithNext(key, value any, next *mapNode) *mapNode {
|
||||||
|
return &mapNode{
|
||||||
|
key: key,
|
||||||
|
value: value,
|
||||||
|
next: next,
|
||||||
|
}
|
||||||
|
}
|
||||||
42
datastructure/hashmap/hashmap_test.go
Normal file
42
datastructure/hashmap/hashmap_test.go
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
package datastructure
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/duke-git/lancet/v2/internal"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestHashMap_PutAndGet(t *testing.T) {
|
||||||
|
assert := internal.NewAssert(t, "TestHashMap_PutAndGet")
|
||||||
|
|
||||||
|
hm := NewHashMap()
|
||||||
|
|
||||||
|
hm.Put("abc", 3)
|
||||||
|
assert.Equal(3, hm.Get("abc"))
|
||||||
|
assert.IsNil(hm.Get("abcd"))
|
||||||
|
|
||||||
|
hm.Put("abc", 4)
|
||||||
|
assert.Equal(4, hm.Get("abc"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestHashMap_Delete(t *testing.T) {
|
||||||
|
assert := internal.NewAssert(t, "TestHashMap_Delete")
|
||||||
|
|
||||||
|
hm := NewHashMap()
|
||||||
|
|
||||||
|
hm.Put("abc", 3)
|
||||||
|
assert.Equal(3, hm.Get("abc"))
|
||||||
|
|
||||||
|
hm.Delete("abc")
|
||||||
|
assert.IsNil(hm.Get("abc"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestHashMap_Contains(t *testing.T) {
|
||||||
|
assert := internal.NewAssert(t, "TestHashMap_Contains")
|
||||||
|
|
||||||
|
hm := NewHashMap()
|
||||||
|
assert.Equal(false, hm.Contains("abc"))
|
||||||
|
|
||||||
|
hm.Put("abc", 3)
|
||||||
|
assert.Equal(true, hm.Contains("abc"))
|
||||||
|
}
|
||||||
@@ -25,6 +25,20 @@ func NewMaxHeap[T any](comparator lancetconstraints.Comparator) *MaxHeap[T] {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BuildMaxHeap builds a MaxHeap instance with data and given comparator.
|
||||||
|
func BuildMaxHeap[T any](data []T, comparator lancetconstraints.Comparator) *MaxHeap[T] {
|
||||||
|
heap := &MaxHeap[T]{
|
||||||
|
data: make([]T, 0, len(data)),
|
||||||
|
comparator: comparator,
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, v := range data {
|
||||||
|
heap.Push(v)
|
||||||
|
}
|
||||||
|
|
||||||
|
return heap
|
||||||
|
}
|
||||||
|
|
||||||
// Push value into the heap
|
// Push value into the heap
|
||||||
func (h *MaxHeap[T]) Push(value T) {
|
func (h *MaxHeap[T]) Push(value T) {
|
||||||
h.data = append(h.data, value)
|
h.data = append(h.data, value)
|
||||||
|
|||||||
@@ -20,6 +20,20 @@ func (c *intComparator) Compare(v1, v2 any) int {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMaxHeap_BuildMaxHeap(t *testing.T) {
|
||||||
|
assert := internal.NewAssert(t, "TestMaxHeap_BuildMaxHeap")
|
||||||
|
|
||||||
|
values := []int{6, 5, 2, 4, 7, 10, 12, 1, 3, 8, 9, 11}
|
||||||
|
heap := BuildMaxHeap(values, &intComparator{})
|
||||||
|
|
||||||
|
expected := []int{12, 9, 11, 4, 8, 10, 7, 1, 3, 5, 6, 2}
|
||||||
|
assert.Equal(expected, heap.data)
|
||||||
|
|
||||||
|
assert.Equal(12, heap.Size())
|
||||||
|
|
||||||
|
heap.PrintStructure()
|
||||||
|
}
|
||||||
|
|
||||||
func TestMaxHeap_Push(t *testing.T) {
|
func TestMaxHeap_Push(t *testing.T) {
|
||||||
assert := internal.NewAssert(t, "TestMaxHeap_Push")
|
assert := internal.NewAssert(t, "TestMaxHeap_Push")
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package datastructure
|
package datastructure
|
||||||
|
|
||||||
// Set is a data container, like slice, but element of set is not duplicate
|
// Set is a data container, like slice, but element of set is not duplicate
|
||||||
type Set[T comparable] map[T]bool
|
type Set[T comparable] map[T]struct{}
|
||||||
|
|
||||||
// NewSet return a instance of set
|
// NewSet return a instance of set
|
||||||
func NewSet[T comparable](values ...T) Set[T] {
|
func NewSet[T comparable](values ...T) Set[T] {
|
||||||
@@ -13,7 +13,7 @@ func NewSet[T comparable](values ...T) Set[T] {
|
|||||||
// Add value to set
|
// Add value to set
|
||||||
func (s Set[T]) Add(values ...T) {
|
func (s Set[T]) Add(values ...T) {
|
||||||
for _, v := range values {
|
for _, v := range values {
|
||||||
s[v] = true
|
s[v] = struct{}{}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ Package algorithm implements some basic algorithm. eg. sort, search.
|
|||||||
|
|
||||||
## Source
|
## Source
|
||||||
|
|
||||||
- [https://github.com/duke-git/lancet/blob/main/algorithm/sorter.go](https://github.com/duke-git/lancet/blob/main/algorithm/sorter.go)
|
- [https://github.com/duke-git/lancet/blob/main/algorithm/sort.go](https://github.com/duke-git/lancet/blob/main/algorithm/sort.go)
|
||||||
- [https://github.com/duke-git/lancet/blob/main/algorithm/search.go](https://github.com/duke-git/lancet/blob/main/algorithm/search.go)
|
- [https://github.com/duke-git/lancet/blob/main/algorithm/search.go](https://github.com/duke-git/lancet/blob/main/algorithm/search.go)
|
||||||
- [https://github.com/duke-git/lancet/blob/main/algorithm/lru_cache.go](https://github.com/duke-git/lancet/blob/main/algorithm/lru_cache.go)
|
- [https://github.com/duke-git/lancet/blob/main/algorithm/lru_cache.go](https://github.com/duke-git/lancet/blob/main/algorithm/lru_cache.go)
|
||||||
|
|
||||||
@@ -248,7 +248,7 @@ func main() {
|
|||||||
<b>Signature:</b>
|
<b>Signature:</b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func QuickSort[T any](slice []T, lowIndex, highIndex int, comparator lancetconstraints.Comparator)
|
func QuickSort[T any](slice []T comparator lancetconstraints.Comparator)
|
||||||
```
|
```
|
||||||
<b>Example:</b>
|
<b>Example:</b>
|
||||||
|
|
||||||
@@ -278,7 +278,7 @@ func main() {
|
|||||||
|
|
||||||
intSlice := []int{2, 1, 5, 3, 6, 4}
|
intSlice := []int{2, 1, 5, 3, 6, 4}
|
||||||
comparator := &intComparator{}
|
comparator := &intComparator{}
|
||||||
algorithm.QuickSort(intSlice, 0, len(intSlice)-1, comparator)
|
algorithm.QuickSort(intSlice, comparator)
|
||||||
|
|
||||||
fmt.Println(intSlice) //[]int{1, 2, 3, 4, 5, 6}
|
fmt.Println(intSlice) //[]int{1, 2, 3, 4, 5, 6}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ algorithm算法包实现一些基本算法,sort,search,lrucache。
|
|||||||
|
|
||||||
## 源码
|
## 源码
|
||||||
|
|
||||||
- [https://github.com/duke-git/lancet/blob/main/algorithm/sorter.go](https://github.com/duke-git/lancet/blob/main/algorithm/sorter.go)
|
- [https://github.com/duke-git/lancet/blob/main/algorithm/sort.go](https://github.com/duke-git/lancet/blob/main/algorithm/sort.go)
|
||||||
- [https://github.com/duke-git/lancet/blob/main/algorithm/search.go](https://github.com/duke-git/lancet/blob/main/algorithm/search.go)
|
- [https://github.com/duke-git/lancet/blob/main/algorithm/search.go](https://github.com/duke-git/lancet/blob/main/algorithm/search.go)
|
||||||
- [https://github.com/duke-git/lancet/blob/main/algorithm/lru_cache.go](https://github.com/duke-git/lancet/blob/main/algorithm/lru_cache.go)
|
- [https://github.com/duke-git/lancet/blob/main/algorithm/lru_cache.go](https://github.com/duke-git/lancet/blob/main/algorithm/lru_cache.go)
|
||||||
|
|
||||||
@@ -249,7 +249,7 @@ func main() {
|
|||||||
<b>函数签名:</b>
|
<b>函数签名:</b>
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func QuickSort[T any](slice []T, lowIndex, highIndex int, comparator lancetconstraints.Comparator) []T
|
func QuickSort[T any](slice []T, comparator lancetconstraints.Comparator) []T
|
||||||
```
|
```
|
||||||
<b>Example:</b>
|
<b>Example:</b>
|
||||||
|
|
||||||
@@ -279,7 +279,7 @@ func main() {
|
|||||||
|
|
||||||
intSlice := []int{2, 1, 5, 3, 6, 4}
|
intSlice := []int{2, 1, 5, 3, 6, 4}
|
||||||
comparator := &intComparator{}
|
comparator := &intComparator{}
|
||||||
algorithm.QuickSort(intSlice, 0, len(intSlice)-1, comparator)
|
algorithm.QuickSort(intSlice, comparator)
|
||||||
|
|
||||||
fmt.Println(intSlice) //[]int{1, 2, 3, 4, 5, 6}
|
fmt.Println(intSlice) //[]int{1, 2, 3, 4, 5, 6}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ func TestHttpGet(t *testing.T) {
|
|||||||
resp, err := HttpGet(url, header)
|
resp, err := HttpGet(url, header)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
t.FailNow()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
body, _ := ioutil.ReadAll(resp.Body)
|
body, _ := ioutil.ReadAll(resp.Body)
|
||||||
@@ -40,7 +39,6 @@ func TestHttpPost(t *testing.T) {
|
|||||||
resp, err := HttpPost(url, header, nil, bodyParams)
|
resp, err := HttpPost(url, header, nil, bodyParams)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
t.FailNow()
|
|
||||||
}
|
}
|
||||||
body, _ := ioutil.ReadAll(resp.Body)
|
body, _ := ioutil.ReadAll(resp.Body)
|
||||||
t.Log("response: ", resp.StatusCode, string(body))
|
t.Log("response: ", resp.StatusCode, string(body))
|
||||||
@@ -67,7 +65,6 @@ func TestHttpPostFormData(t *testing.T) {
|
|||||||
resp, err := HttpPost(apiUrl, header, postData, nil)
|
resp, err := HttpPost(apiUrl, header, postData, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
t.FailNow()
|
|
||||||
}
|
}
|
||||||
body, _ := ioutil.ReadAll(resp.Body)
|
body, _ := ioutil.ReadAll(resp.Body)
|
||||||
t.Log("response: ", resp.StatusCode, string(body))
|
t.Log("response: ", resp.StatusCode, string(body))
|
||||||
@@ -89,7 +86,6 @@ func TestHttpPut(t *testing.T) {
|
|||||||
resp, err := HttpPut(url, header, nil, bodyParams)
|
resp, err := HttpPut(url, header, nil, bodyParams)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
t.FailNow()
|
|
||||||
}
|
}
|
||||||
body, _ := ioutil.ReadAll(resp.Body)
|
body, _ := ioutil.ReadAll(resp.Body)
|
||||||
t.Log("response: ", resp.StatusCode, string(body))
|
t.Log("response: ", resp.StatusCode, string(body))
|
||||||
@@ -111,7 +107,6 @@ func TestHttpPatch(t *testing.T) {
|
|||||||
resp, err := HttpPatch(url, header, nil, bodyParams)
|
resp, err := HttpPatch(url, header, nil, bodyParams)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
t.FailNow()
|
|
||||||
}
|
}
|
||||||
body, _ := ioutil.ReadAll(resp.Body)
|
body, _ := ioutil.ReadAll(resp.Body)
|
||||||
t.Log("response: ", resp.StatusCode, string(body))
|
t.Log("response: ", resp.StatusCode, string(body))
|
||||||
@@ -122,7 +117,6 @@ func TestHttpDelete(t *testing.T) {
|
|||||||
resp, err := HttpDelete(url)
|
resp, err := HttpDelete(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
t.FailNow()
|
|
||||||
}
|
}
|
||||||
body, _ := ioutil.ReadAll(resp.Body)
|
body, _ := ioutil.ReadAll(resp.Body)
|
||||||
t.Log("response: ", resp.StatusCode, string(body))
|
t.Log("response: ", resp.StatusCode, string(body))
|
||||||
@@ -148,7 +142,6 @@ func TestParseResponse(t *testing.T) {
|
|||||||
resp, err := HttpGet(url, header)
|
resp, err := HttpGet(url, header)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
t.FailNow()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Todo struct {
|
type Todo struct {
|
||||||
@@ -162,7 +155,6 @@ func TestParseResponse(t *testing.T) {
|
|||||||
err = ParseHttpResponse(resp, toDoResp)
|
err = ParseHttpResponse(resp, toDoResp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
t.FailNow()
|
|
||||||
}
|
}
|
||||||
t.Log("response: ", toDoResp)
|
t.Log("response: ", toDoResp)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user