riri

package module
v0.0.0-...-0b4a4e5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 27, 2022 License: MIT Imports: 7 Imported by: 0

README

riri

被啰嗦到网络请求烦到了, 内心难受

人生一片黑暗的社畜又替最为厌恶的人背上了无力偿还的债务, 让本就在贫困线边缘挣扎的自闭five更加绝望

在不确定的未来删号重练发生前, 妄图挤些代码, 自欺欺人

参考平时用的Postman, 链式调用的网络请求

莫名其妙

目前只能struct套一层interface 可惜不能无限套娃

暂时不想传变量, 说不定后续会改成struct套娃

使用之前瞎写的错误追踪来输出错误信息

使用gin作为测试

为了方便区分环境, 补充了riri.Group用来生成URL, 后续可能会做进一步集成

花里胡哨

result, kerr := GET(url).Params.Set(map[string]string{
    "1": "2",
}).Result()

.Result() 直接返回[]byte(body)与kazaana.Error(保存调用栈的错误回调)

若要更接近原生返回值, 可以使用.Do()

拖泥带水

随缘更新, 由于思路比较混乱, 方法不会咋地稳定, 基本属于瞎胡闹, 精神状态好了可能会补上说明

  • interface

interface的缺点估计就在于没法非常完美地区分方法, 但使用struct套娃又会引入除必要方法外多余的结构体, 后续发展方向还未考虑好

  • Group

对Group的进一步设想如下

tsGroup := riri.Group(...)
resData, kerr := tsGroup.Path("/11").Path("/22").GET.Result()

极大概率由于拖延与懒癌用不到

  • 关于错误

是否应该根据http状态码直接抛出错误? 还是手动处理结果?

  • 解析模版

有许多简单请求后的处理行为完全一致, 是否应该想办法优化一下这类可能出现的重复代码?

  • Request

转为小写, 不对外开放, 强制全流程链式调用?

  • kazaana

先让子弹飞一会, 不开洞了?

  • Client 配置

只有默认似乎不大行, 也许得加点自定义

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Body

type Body interface {
	FormData(f map[string]FormDataValue) *Request
	JSON(v interface{}) *Request
	Binary(data []byte, contentType ...string) *Request
}

Body body

type FormDataValue

type FormDataValue struct {
	Text string

	FileName string
	FileData []byte
}

FormDataValue type Text if len(FileData)<=0 || len(FileName)<=0

type Group

type Group struct {
	BaseURL func() string
}

Group is used to generate adaptive url path in different environments.

func (Group) Path

func (slf Group) Path(path string) PreRequest

Path return baseURL + path

type Headers

type Headers interface {
	Add(h map[string]string) *Request
}

Headers headers

type Params

type Params interface {
	Set(p map[string]string) *Request
	// contains filtered or unexported methods
}

Params query_params

cover request line

type PreRequest

type PreRequest string

PreRequest url

func (PreRequest) GET

func (slf PreRequest) GET() Request

GET riri.GET

func (PreRequest) POST

func (slf PreRequest) POST() Request

POST riri.POST

type Request

type Request struct {
	Params
	Headers
	Body
	// contains filtered or unexported fields
}

Request base

func GET

func GET(url string) Request

GET request

func POST

func POST(url string) Request

POST request

func (*Request) Add

func (slf *Request) Add(h map[string]string) *Request

Add headers

func (*Request) Binary

func (r *Request) Binary(data []byte, contentType ...string) *Request

Binary body binary

func (Request) BindJSON

func (slf Request) BindJSON(ptr interface{}) ([]byte, kazaana.Error)

BindJSON .Result() -> JSON

without json.Number

func (Request) Do

func (slf Request) Do() (*http.Response, kazaana.Error)

Do client.Do

func (*Request) FormData

func (r *Request) FormData(f map[string]FormDataValue) *Request

FormData body raw form-data

func (*Request) JSON

func (r *Request) JSON(v interface{}) *Request

JSON body raw JSON

func (Request) Result

func (slf Request) Result() ([]byte, kazaana.Error)

Result res body data

func (*Request) Set

func (r *Request) Set(p map[string]string) *Request

Set query params

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL