curlimport

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package curlimport turns a curl command line into a `.http` request block, the reverse of `apic curl`: the common flags map onto the request line, headers, body and auth; the rest is reported, never fatal.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Name

func Name(r *Request) string

Name derives a request name from the method and path when --name is not given: `POST /todos/42` becomes post-todos-42.

func Render

func Render(r *Request, name, baseURL string) string

Render writes the request as a `###` block. baseURL, when it prefixes the URL, is replaced by {{baseUrl}}.

func SplitsBlock

func SplitsBlock(body string) bool

SplitsBlock reports whether the inline body would be misread by the .http parser: a line starting with ### opens a new request block and a body starting with `< ` refers to a file. Such a body belongs in a side file (BodyFile).

Types

type Header struct{ Name, Value string }

Header is one -H header.

type Part

type Part struct {
	Name        string
	Value       string
	File        string // name=@path
	Filename    string // ;filename=
	ContentType string // ;type=
}

Part is one -F field.

type Request

type Request struct {
	Method   string
	URL      string
	Headers  []Header
	Body     string // inline body
	BodyFile string // `-d @file`: sent as `< ./file`
	Parts    []Part // -F fields, a multipart body
	User     string // -u user:password, as `# @auth basic`
	Insecure bool   // -k
	Follow   bool   // -L
	// HTTPVersion is HTTP/1.1 for --http1.1 and HTTP/2 for --http2, written
	// on the request line; empty otherwise.
	HTTPVersion string
	Warnings    []string
}

Request is what a curl command line asked for.

func Parse

func Parse(command string) (*Request, error)

Parse reads a curl command line, with its shell quoting and line continuations, and returns the request it describes. Unknown flags are warnings, not errors; an unreadable line or a missing URL is an error.

Jump to

Keyboard shortcuts

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