This repository has been archived by the owner on Dec 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
nic.go
94 lines (77 loc) · 2.47 KB
/
nic.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package nic
import (
"errors"
)
const (
version = "0.3.1"
userAgent = "golang-nic/0.3.1"
author = "iv4n"
copyright = "Copyright 2019 iv4n"
)
var (
// ErrInvalidMethod will be throwed when method not in
// [HEAD, GET, POST, DELETE, OPTIONS, PUT, PATCH, CONNECT, TRACE]
ErrInvalidMethod = errors.New("nic: Method is invalid")
// ErrFileInfo will be throwed when fileinfo is invalid
ErrFileInfo = errors.New("nic: Invalid file information")
// ErrParamConflict will be throwed when options params conflict
// e.g. files + data
// json + data
// ...
ErrParamConflict = errors.New("nic: Options param conflict")
// ErrUnrecognizedEncoding will be throwed while changing response encoding
// if encoding is not recognized
ErrUnrecognizedEncoding = errors.New("nic: Unrecognized encoding")
// ErrNotJsonResponse will be throwed when response not a json
// but invoke Json() method
ErrNotJsonResponse = errors.New("nic: Not a Json response")
// ErrHookFuncMaxLimit will be throwed when the number of hook functions
// more than MaxLimit = 8
ErrHookFuncMaxLimit = errors.New("nic: The number of hook functions must be less than 8")
// ErrIndexOutofBound means the index out of bound
ErrIndexOutofBound = errors.New("nic: Index out of bound")
)
const (
HEAD = "HEAD"
GET = "GET"
POST = "POST"
DELETE = "DELETE"
OPTIONS = "OPTIONS"
PUT = "PUT"
PATCH = "PATCH"
)
// Get implemented by Session.Get
func Get(url string, option Option) (*Response, error) {
session := NewSession()
return session.Get(url, option)
}
// Post implemented by Session.Post
func Post(url string, option Option) (*Response, error) {
session := NewSession()
return session.Post(url, option)
}
// Head implemented by Session.Head
func Head(url string, option Option) (*Response, error) {
session := NewSession()
return session.Head(url, option)
}
// Delete implemented by Session.Delete
func Delete(url string, option Option) (*Response, error) {
session := NewSession()
return session.Delete(url, option)
}
// Options implemented by Session.Options
func Options(url string, option Option) (*Response, error) {
session := NewSession()
return session.Options(url, option)
}
// Put implemented by Session.Put
func Put(url string, option Option) (*Response, error) {
session := NewSession()
return session.Put(url, option)
}
// Patch implemented by Session.Patch
func Patch(url string, option Option) (*Response, error) {
session := NewSession()
return session.Patch(url, option)
}