gurl

package module
v0.0.0-...-4282750 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2024 License: MIT Imports: 62 Imported by: 0

README

gurl

Gurl is a Go implemented CLI cURL-like tool for humans

gurl [flags] [METHOD] URL [ITEM [ITEM]]

Go implemented CLI cURL-like tool for humans. gurl can be used for testing, debugging, and generally interacting with HTTP servers.

Inspired by Httpie. Thanks to the author, Jakub.

Features:

  1. 2023年05月18日 INTERACTIVE=0 gurl 禁止交互模式,否则 请求参数值/地址中的注入 @age 将被解析成插值模式,会要求从命令行输入

  2. 2023年05月17日 多网卡时,指定通过指定 IP,连接服务端, export LOCAL_IP=ip

  3. 2022年11月21日 支持深度美化 JSON 字符串(包括内嵌JSON字符串),例如 gurl -b '{"xx":"{\"age\":100}"}' -pBf

  4. 2022年09月14日 支持指定 DNS 解析服务器,例如 gurl http://a.cn:5003/echo -dns 127.0.0.1

  5. 2022年08月31日 文件下载时,支持断点续传

  6. 2022年05月24日 支持 从文件按行读取请求体,发送多次请求,例如 gurl :9200/person1/_doc/@ksuid -b persons.txt:line -auth ZWxhc3RpYzoxcWF6WkFRIQ -n0 -pucb -ugly

  7. 2022年03月09日 支持 ca

    $ httplive &
    $ gurl https://localhost:5003/v -ca .cert/localhost.pem  -pb
    {
      "build": "2022-03-09T22:51:14+0800",
      "git": "19d2de6@2022-03-09T17:26:53+08:00",
      "go": "go1.17.8_darwin/amd64",
      "version": "1.3.5"
    }
    
  8. 2022年02月21日 支持 timeout 参数,e.g. -timeout=0

  9. 2022年02月09日 支持多 URL. gurl 192.168.126.{16,18,182}:15002/kv -pb gurl 192.168.126.{16,18,182}:15002/kv -pb POST v==12345

  10. 2022年01月06日 支持查询值从文件中读取 gurl -raw b.n:10014/query q==@query.sql

$ gurl PUT httpbin.org/put hello=world
PUT /put? HTTP/1.1
Host: httpbin.org
Accept: application/json
Accept-Encoding: gzip, deflate
Content-Type: application/json
User-Agent: gurl/0.1.0

{"hello":"world"}

HTTP/1.1 200 OK
Access-Control-Allow-Credentials: true
Date: Thu, 06 Jan 2022 03:38:08 GMT
Content-Type: application/json
Content-Length: 486
Connection: keep-alive
Server: gunicorn/19.9.0
Access-Control-Allow-Origin: *

{
  "args": {},
  "data": "{\"hello\":\"world\"}\n",
  "files": {},
  "form": {},
  "headers": {
    "Accept": "application/json",
    "Accept-Encoding": "gzip, deflate",
    "Content-Length": "18",
    "Content-Type": "application/json",
    "Host": "httpbin.org",
    "User-Agent": "gurl/0.1.0",
    "X-Amzn-Trace-Id": "Root=1-61d66420-230d9c070cfeffbc477fc755"
  },
  "json": {
    "hello": "world"
  },
  "origin": "43.245.222.139",
  "url": "http://httpbin.org/put"
}

Docker

# Build the docker image
$ docker build -t bingoohuang/ngg/gurl .

# Run gurl in a container
$ docker run --rm -it --net=host bingoohuang/ngg/gurl example.org

Main Features

  • Expressive and intuitive syntax
  • Built-in JSON support
  • Forms and file uploads
  • HTTPS, proxies, and authentication
  • Arbitrary request data
  • Custom headers

Installation

Install with Modules - Go 1.11 or higher

If you only want to install the gurl tool:

go get -u github.com/bingoohuang/ngg/gurl

If you want a mutable copy of source code:

git clone https://github.com/bingoohuang/ngg/gurl ;# clone outside of GOPATH
cd gurl
go install

Make sure the ~/go/bin is added into $PATH.

Install without Modules - Before Go 1.11
go get -u github.com/bingoohuang/ngg/gurl

Make sure the $GOPATH/bin is added into $PATH.

Usage

Hello World:

$ gurl beego.me

Synopsis:

gurl [flags] [METHOD] URL [ITEM [ITEM]]

See also gurl --help.

Examples

Basic settings - HTTP method, HTTP headers and JSON data:

$ gurl PUT example.org X-API-Token:123 name=John

Any custom HTTP method (such as WebDAV, etc.):

$ gurl -method=PROPFIND example.org name=John

Submitting forms:

$ gurl -form=true POST example.org hello=World

See the request that is being sent using one of the output options:

$ gurl -print="Hhb" example.org

Use Github API to post a comment on an issue with authentication:

$ gurl -a USERNAME POST https://api.github.com/repos/bingoohuang/ngg/gurl/issues/1/comments body='gurl is awesome!'

Upload a file using redirected input:

$ gurl example.org < file.json

Download a file and save it via redirected output:

$ gurl example.org/file > file

Download a file wget style:

$ gurl -download=true example.org/file

Set a custom Host header to work around missing DNS records:

$ gurl localhost:8000 Host:example.com

Following is the detailed documentation. It covers the command syntax, advanced usage, and also features additional examples.

HTTP Method

The name of the HTTP method comes right before the URL argument:

$ gurl DELETE example.org/todos/7

which looks similar to the actual Request-Line that is sent:

DELETE /todos/7 HTTP/1.1

When the METHOD argument is omitted from the command, gurl defaults to either GET (if there is no request data) or POST ( with request data).

Request URL

The only information gurl needs to perform a request is a URL. The default scheme is, somewhat unsurprisingly, http://, and can be omitted from the argument – gurl example.org works just fine.

Additionally, curl-like shorthand for localhost is supported. This means that, for example :3000 would expand to http://localhost:3000 If the port is omitted, then port 80 is assumed.

$ gurl :/foo

GET /foo HTTP/1.1
Host: localhost

$ gurl :3000/bar

GET /bar HTTP/1.1
Host: localhost:3000

$ gurl :

GET / HTTP/1.1
Host: localhost

If you find yourself manually constructing URLs with query string parameters on the terminal, you may appreciate the param=value syntax for appending URL parameters so that you don't have to worry about escaping the & separators. To search for gurl on Google Images you could use this command:

$ gurl GET www.google.com search=gurl tbm=isch

GET /?search=gurl&tbm=isch HTTP/1.1

Request Items

There are a few different request item types that provide a convenient mechanism for specifying HTTP headers, simple JSON and form data, files, and URL parameters.

They are key/value pairs specified after the URL. All have in common that they become part of the actual request that is sent and that their type is distinguished only by the separator used: :, =, :=, @, =@, and :=@. The ones with an @ expect a file path as value.

Item Type Description
HTTP Headers Name:Value Arbitrary HTTP header, e.g. X-API-Token:123.
Data Fields field=value Request data fields to be serialized as a JSON object (default), or to be form-encoded (--form, -f).
Form File Fields field@/dir/file Only available with -form, -f. For example screenshot@~/Pictures/img.png. The presence of a file field results in a multipart/form-data request.
Form Fields from file field=@file.txt read content from file as value
Raw JSON fields field:=json, field:=@file.json Useful when sending JSON and one or more fields need to be a Boolean, Number, nested Object, or an Array, e.g., meals:='["ham","spam"]' or pies:=[1,2,3] (note the quotes).

You can use \ to escape characters that shouldn't be used as separators (or parts thereof). For instance, foo==bar will become a data key/value pair (foo= and bar) instead of a URL parameter.

You can also quote values, e.g. foo="bar baz".

JSON

JSON is the lingua franca of modern web services and it is also the implicit content type gurl by default uses:

If your command includes some data items, they are serialized as a JSON object by default. gurl also automatically sets the following headers, both of which can be overridden:

header value
Content-Type application/json
Accept application/json

You can use --json=true, -j=true to explicitly set Accept to application/json regardless of whether you are sending data (it's a shortcut for setting the header via the usual header notation – gurl url Accept:application/json).

Simple example:

$ gurl PUT example.org name=John email=john@example.org
PUT / HTTP/1.1
Accept: application/json
Accept-Encoding: gzip, deflate
Content-Type: application/json
Host: example.org

{
    "name": "John",
    "email": "john@example.org"
}

Even custom/vendored media types that have a json format are getting detected, as long as they implement a json type response and contain a json in their declared form:

$ gurl GET example.org/user/1 Accept:application/vnd.example.v2.0+json
GET / HTTP/1.1
Accept: application/vnd.example.v2.0+json
Accept-Encoding: gzip, deflate
Content-Type: application/vnd.example.v2.0+json
Host: example.org

{
    "name": "John",
    "email": "john@example.org"
}

Non-string fields use the := separator, which allows you to embed raw JSON into the resulting object. Text and raw JSON files can also be embedded into fields using =@ and :=@:

$ gurl PUT api.example.com/person/1 \
name=John \
age:=29 married:=false hobbies:='["http", "pies"]' \  # Raw JSON
description=@about-john.txt \   # Embed text file
bookmarks:=@bookmarks.json      # Embed JSON file

PUT /person/1 HTTP/1.1
Accept: application/json
Content-Type: application/json
Host: api.example.com

{
    "age": 29,
    "hobbies": [
        "http",
        "pies"
    ],
    "description": "John is a nice guy who likes pies.",
    "married": false,
    "name": "John",
    "bookmarks": {
        "HTTPie": "http://httpie.org",
    }
}

Send JSON data stored in a file (see redirected input for more examples):

$ gurl POST api.example.com/person/1 < person.json

Forms

Submitting forms are very similar to sending JSON requests. Often the only difference is in adding the -form=true , -f option, which ensures that data fields are serialized correctly and Content-Type is set to, application/x-www-form-urlencoded; charset=utf-8.

It is possible to make form data the implicit content type instead of JSON via the config file.

Regular Forms
$ gurl -f POST api.example.org/person/1 name='John Smith' \
email=john@example.org

POST /person/1 HTTP/1.1
Content-Type: application/x-www-form-urlencoded; charset=utf-8

name=John+Smith&email=john%40example.org
File Upload Forms

If one or more file fields is present, the serialization and content type is multipart/form-data:

$ gurl -f POST example.com/jobs name='John Smith' cv@~/Documents/cv.pdf

The request above is the same as if the following HTML form were submitted:


<form enctype="multipart/form-data" method="post" action="http://example.com/jobs">
    <input type="text" name="name" />
    <input type="file" name="cv" />
</form>

Note that @ is used to simulate a file upload form field.

HTTP Headers

To set custom headers you can use the Header:Value notation:

$ gurl example.org  User-Agent:Bacon/1.0  'Cookie:valued-visitor=yes;foo=bar'  \
X-Foo:Bar  Referer:http://beego.me/

GET / HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Cookie: valued-visitor=yes;foo=bar
Host: example.org
Referer: http://beego.me/
User-Agent: Bacon/1.0
X-Foo: Bar

There are a couple of default headers that gurl sets:

GET / HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
User-Agent: gurl/<version>
Host: <taken-from-URL>

Any of the default headers can be overridden.

Authentication

Basic auth:

$ gurl -a=username:password example.org

Proxies

You can specify proxies to be used through the --proxy argument for each protocol (which is included in the value in case of redirects across protocols):

$ gurl --proxy=http://10.10.1.10:3128 example.org

With Basic authentication:

$ gurl --proxy=http://user:pass@10.10.1.10:3128 example.org

You can also configure proxies by environment variables HTTP_PROXY and HTTPS_PROXY, and the underlying Requests library will pick them up as well. If you want to disable proxies configured through the environment variables for certain hosts, you can specify them in NO_PROXY.

In your ~/.bash_profile:

export HTTP_PROXY=http://10.10.1.10:3128
export HTTPS_PROXY=https://10.10.1.10:1080
export NO_PROXY=localhost,example.com

usages examples

$ gurl POST name=@姓名_1 name2=@姓名_2 name3=@姓名_1 name4=@姓名_2 name5=@姓名 name6=@姓名
POST / HTTP/1.1
Host: dry.run.url
Accept: application/json
Accept-Encoding: gzip, deflate
Content-Type: application/json
Gurl-Date: Fri, 06 May 2022 00:45:34 GMT
User-Agent: gurl/1.0.0

{
  "name": "轩辕局徖",
  "name2": "夏嬮耤",
  "name3": "轩辕局徖",
  "name4": "夏嬮耤",
  "name5": "寇碭韅",
  "name6": "尤搮蜃"
}

resources

  1. rs/curlie The power of curl, the ease of use of httpie.
  2. Hurl is a command line tool that runs HTTP requests defined in a simple plain text format.
  3. httpretty prints the HTTP requests you make with Go pretty on your terminal.

tlcp support

# 生成根证书和服务端证书
$ tlcp -m localhost
# 生成客户端证书
$ tlcp -c -m localhost
# 启动国密 https 服务
$ tlcp -l :8443 --ecdhe --verify-client-cert -r root.pem -C localhost.pem -C localhost.key -C localhost.pem -C localhost.key
listen on :8443
# 调用验证
$ TLS_VERIFY=1 TLCP=1 TLCP_CERTS=localhost-client.pem,localhost-client.key,localhost-client.pem,localhost-client.key CERT=root.pem gurl https://localhost:8443 
Hello GoTLCP!

Documentation

Index

Constants

View Source
const (
	Gray = uint8(iota + 90)

	Green
	Yellow

	Magenta
	Cyan

	EndColor = "\033[0m"
)
View Source
const (
	MaxPayloadSize        = "MAX_PAYLOAD_SIZE"
	DefaultMaxPayloadSize = 1024 * 1024
)
View Source
const (
	DefaultRefreshRate = 200 * time.Millisecond
)
View Source
const DryRequestURL = `http://dry.run.url`

Variables

View Source
var Color = func(str string, color uint8) string {
	if hasStdoutDevice {
		return fmt.Sprintf("%s%s%s", ColorStart(color), str, EndColor)
	}

	return str
}
View Source
var (

	// ErrWrongCodeForByteRange is returned if the client sends a request
	// with a Range header but the server returns a 2xx or 3xx code other
	// than 206 Partial Content.
	ErrWrongCodeForByteRange = errors.New("expected HTTP 206 from byte range request")
)

Functions

func AdjustPrintOption

func AdjustPrintOption(s *string, r rune, flags uint32)

func ColorStart

func ColorStart(color uint8) string

func ColorfulHTML

func ColorfulHTML(str string) string

func ColorfulRequest

func ColorfulRequest(str string) string

func ColorfulResponse

func ColorfulResponse(str string, isJSON bool) string

func DecodePemBlocks

func DecodePemBlocks(certInput string) (blocks []*pem.Block)

DecodePemBlocks 解析 PEM 字符串中的块

func DecodePemChain

func DecodePemChain(certInput string) (chain [][]byte)

DecodePemChain 解析 PEM 字符串中的证书链 thanks https://gist.github.com/laher/5795578

func Eval

func Eval(s string) (string, error)

func GetVar

func GetVar(name string) string

func Getenv

func Getenv(keys ...string) string

func HasAnyPrintOptions

func HasAnyPrintOptions(flags ...uint32) bool

func HasPrintOption

func HasPrintOption(flags uint32) bool

func HashFile

func HashFile(f string, h hash.Hash) ([]byte, error)

func LinesChan

func LinesChan(filePath string) (func() (string, error), error)

LinesChan read file into lines.

func LoadCerts

func LoadCerts(certFiles []string) (certs []tls.Certificate, err error)

func NewGzipReader

func NewGzipReader(source io.Reader) *io.PipeReader

func ReadLine

func ReadLine(fns ...LineConfigFn) (string, error)

func RemoveChars

func RemoveChars(input, cutset string) string

func Resolve

func Resolve(host, dnsServer string) ([]string, error)

Resolve resolves host www.google.co by dnsServer like 8.8.8.8:5

func Run

func Run()

func RunBench

func RunBench(b *Request, thinkerFn func())

func ScanLines

func ScanLines(data []byte, atEOF bool) (advance int, token []byte, err error)

ScanLines is a split function for a Scanner that returns each line of text, with end-of-line marker. The returned line may be empty. The end-of-line marker is one optional carriage return followed by one mandatory newline. In regular expression notation, it is `\r?\n`. The last non-empty line of input will be returned even if it has no newline.

func Stat

func Stat(name string) (int64, bool, error)

func TeeReadeCloser

func TeeReadeCloser(r io.ReadCloser, w io.Writer) io.ReadCloser

TeeReadeCloser returns a ReadCloser that writes to w what it reads from r. All reads from r performed through it are matched with corresponding writes to w. There is no internal buffering - the write must complete before the read completes. Any error encountered while writing is reported as a read error.

func Try

func Try[T any](a T, err error) T

Types

type DialContextFn

type DialContextFn func(ctx context.Context, network, address string) (net.Conn, error)

func TimeoutDialer

func TimeoutDialer(cTimeout time.Duration, tlsConfig *tls.Config, debug bool, r, w *int64) DialContextFn

TimeoutDialer returns functions of connection dialer with timeout settings for http.Transport Dial field.

type InfluxQueryResult

type InfluxQueryResult struct {
	Results []struct {
		Series      []Series `json:"series"`
		StatementID int      `json:"statement_id"`
	} `json:"results"`
}

type LineConfig

type LineConfig struct {
	Prompt      string
	HistoryFile string
	Suffix      []string
	TrimSuffix  bool
}

type LineConfigFn

type LineConfigFn func(config *LineConfig)

func WithHistoryFile

func WithHistoryFile(historyFile string) LineConfigFn

func WithPrompt

func WithPrompt(prompt string) LineConfigFn

func WithTrimSuffix

func WithTrimSuffix(trimSuffix bool) LineConfigFn

type LogRedirects

type LogRedirects struct {
	http.RoundTripper
}

LogRedirects log redirect refer: Go HTTP Redirect的知识点总结 https://colobu.com/2017/04/19/go-http-redirect/

func (LogRedirects) RoundTrip

func (l LogRedirects) RoundTrip(req *http.Request) (resp *http.Response, err error)

type MyConn

type MyConn struct {
	net.Conn
	// contains filtered or unexported fields
}

func NewMyConn

func NewMyConn(conn net.Conn, debug bool, r, w *int64) *MyConn

func (*MyConn) Read

func (c *MyConn) Read(b []byte) (n int, err error)

func (*MyConn) Write

func (c *MyConn) Write(b []byte) (n int, err error)

type ProgressBar

type ProgressBar struct {
	BarStart string
	CurrentN string

	Current     string
	Empty       string
	BarEnd      string
	Total       int64
	RefreshRate time.Duration

	ShowFinalTime bool

	ShowSpeed, ShowTimeLeft, ShowBar bool
	ShowPercent, ShowCounters        bool
	// contains filtered or unexported fields
}

func NewProgressBar

func NewProgressBar(total int64) (pb *ProgressBar)

func (*ProgressBar) Add

func (pb *ProgressBar) Add(add int) int

Add to current value

func (*ProgressBar) Add64

func (pb *ProgressBar) Add64(add int64) int64

func (*ProgressBar) Finish

func (pb *ProgressBar) Finish()

Finish print

func (*ProgressBar) Increment

func (pb *ProgressBar) Increment() int

Increment current value

func (*ProgressBar) Set

func (pb *ProgressBar) Set(current int)

Set current value

func (*ProgressBar) SetTotal

func (pb *ProgressBar) SetTotal(total int64)

func (*ProgressBar) Start

func (pb *ProgressBar) Start() *ProgressBar

func (*ProgressBar) Update

func (pb *ProgressBar) Update()

Update the current state of the progressbar

func (*ProgressBar) Write

func (pb *ProgressBar) Write(p []byte) (n int, err error)

Write implement io.Writer

type ProgressBarReader

type ProgressBarReader struct {
	io.ReadCloser
	// contains filtered or unexported fields
}

func (*ProgressBarReader) Read

func (pr *ProgressBarReader) Read(p []byte) (n int, err error)

type RateLimitDirection

type RateLimitDirection int
const (
	RateLimitBoth RateLimitDirection = iota
	RateLimitRequest
	RateLimitResponse
)

type RateLimitFlag

type RateLimitFlag struct {
	Val       *uint64
	Direction RateLimitDirection
}

func NewRateLimitFlag

func NewRateLimitFlag() *RateLimitFlag

func (*RateLimitFlag) Enabled

func (i *RateLimitFlag) Enabled() bool

func (*RateLimitFlag) Float64

func (i *RateLimitFlag) Float64() float64

func (*RateLimitFlag) IsForReq

func (i *RateLimitFlag) IsForReq() bool

func (*RateLimitFlag) IsForRsp

func (i *RateLimitFlag) IsForRsp() bool

func (*RateLimitFlag) Set

func (i *RateLimitFlag) Set(value string) (err error)

func (*RateLimitFlag) String

func (i *RateLimitFlag) String() string

func (*RateLimitFlag) Type

func (i *RateLimitFlag) Type() string

type Request

type Request struct {
	Transport http.RoundTripper

	Req *http.Request

	ConnInfo httptrace.GotConnInfo

	Setting Settings

	Timeout time.Duration

	DryRequest bool

	DisableKeepAlives bool
	// contains filtered or unexported fields
}

Request provides more useful methods for requesting one url than http.Request.

func NewRequest

func NewRequest(rawURL, method string) *Request

NewRequest return *Request with specific method

func (*Request) Body

func (b *Request) Body(data any) *Request

func (*Request) BodyAndSize

func (b *Request) BodyAndSize(body io.ReadCloser, size int64) *Request

func (*Request) BodyCh

func (b *Request) BodyCh(data func() (string, error)) *Request

BodyCh set body channel..

func (*Request) BodyFileLines

func (b *Request) BodyFileLines(t string) bool

func (*Request) BodyString

func (b *Request) BodyString(s string)

func (*Request) BuildURL

func (b *Request) BuildURL()

func (*Request) Bytes

func (b *Request) Bytes() ([]byte, error)

Bytes returns the body []byte in response. it calls Response inner.

func (*Request) DumpBody

func (b *Request) DumpBody(isdump bool) *Request

DumpBody Dump Body.

func (*Request) DumpRequest

func (b *Request) DumpRequest(dumpRequest bool) *Request

DumpRequest sets show debug or not when executing request.

func (*Request) Header

func (b *Request) Header(key, value string) *Request

Header add header item string in request.

func (*Request) NextBody

func (b *Request) NextBody() error

func (*Request) Param

func (b *Request) Param(key, value string) *Request

Param adds query param in to request. params build query string as ?key1=value1&key2=value2...

func (*Request) PostFile

func (b *Request) PostFile(formname, filename string) *Request

func (*Request) Query

func (b *Request) Query(key, value string) *Request

Query adds query param in to request. params build query string as ?key1=value1&key2=value2...

func (*Request) RefreshBody

func (b *Request) RefreshBody() *Request

RefreshBody 刷新 body 值,在 -n2 以上时使用

func (*Request) Reset

func (b *Request) Reset()

func (*Request) Response

func (b *Request) Response() (*http.Response, error)

func (*Request) SendOut

func (b *Request) SendOut() (*http.Response, error)

func (*Request) SetBasicAuth

func (b *Request) SetBasicAuth(username, password string) *Request

SetBasicAuth sets the request's Authorization header to use HTTP Basic Authentication with the provided username and password.

func (*Request) SetCookie

func (b *Request) SetCookie(cookie *http.Cookie) *Request

SetCookie add cookie into request.

func (*Request) SetEnableCookie

func (b *Request) SetEnableCookie(enable bool) *Request

SetEnableCookie sets enable/disable cookiejar

func (*Request) SetHost

func (b *Request) SetHost(host string) *Request

SetHost Set HOST

func (*Request) SetProtocolVersion

func (b *Request) SetProtocolVersion(vers string) *Request

SetProtocolVersion Set the protocol version for incoming requests. Client requests always use HTTP/1.1.

func (*Request) SetProxy

func (b *Request) SetProxy(proxy func(*http.Request) (*url.URL, error)) *Request

SetProxy Set http proxy example:

func(Req *http.Request) (*url.URL, error) {
	u, _ := url.ParseRequestURI("http://127.0.0.1:8118")
	return u, nil
}

func (*Request) SetTLSClientConfig

func (b *Request) SetTLSClientConfig(config *tls.Config) *Request

SetTLSClientConfig sets tls connection configurations if visiting https url.

func (*Request) SetTimeout

func (b *Request) SetTimeout(connectTimeout time.Duration) *Request

SetTimeout sets connect time out and read-write time out for BeegoRequest.

func (*Request) SetTransport

func (b *Request) SetTransport(transport http.RoundTripper) *Request

SetTransport Set transport to

func (*Request) SetUserAgent

func (b *Request) SetUserAgent(useragent string) *Request

SetUserAgent sets User-Agent header field

func (*Request) SetupTransport

func (b *Request) SetupTransport()

func (*Request) String

func (b *Request) String() (string, error)

String returns the body string in response. it calls Response inner.

func (*Request) ToFile

func (b *Request) ToFile(filename string) error

ToFile saves the body data in response to one file. it calls Response inner.

func (*Request) ToJSON

func (b *Request) ToJSON(v any) error

ToJSON returns the map that marshals from the body bytes as json in response . it calls Response inner.

func (*Request) ToXML

func (b *Request) ToXML(v any) error

ToXML returns the map that marshals from the body bytes as xml in response . it calls Response inner.

type Series

type Series struct {
	Name    string   `json:"name"`
	Columns []string `json:"columns"`
	Values  [][]any  `json:"values"`
}

type Settings

type Settings struct {
	Transport      http.RoundTripper
	TLSConfig      *tls.Config
	Proxy          func(*http.Request) (*url.URL, error)
	UserAgent      string
	ConnectTimeout time.Duration
	DumpRequest    bool
	EnableCookie   bool
	DumpBody       bool
}

Settings .

type Valuer

type Valuer struct {
	Map map[string]any
	*jj.GenContext
	InteractiveMode bool
}

func NewValuer

func NewValuer(interactiveMode bool) *Valuer

func (*Valuer) ClearCache

func (v *Valuer) ClearCache()

func (*Valuer) Value

func (v *Valuer) Value(name, params, expr string) (any, error)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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