curlreq

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2025 License: MIT Imports: 13 Imported by: 2

README

curlreq

build Go Reference Coverage Code to Test Ratio Test Execution Time

curlreq creates *http.Request from curl command.

Usage

package main

import (
	"fmt"
	"log"
	"net/http"

	"github.com/k1LoW/curlreq"
)

func main() {
	cmd := "curl https://example.com"
	req, err := curlreq.NewRequest(cmd)
	if err != nil {
		log.Fatal(err)
	}
	client := http.DefaultClient
	resp, err := client.Do(req)
	if err != nil {
		log.Fatal(err)
	}
	defer resp.Body.Close()

	fmt.Println(resp.StatusCode)

	// Output:
	// 200
}

Reference

  • tj/parse-curl.js: Parse curl commands, returning an object representing the request.

Documentation

Overview

Example
package main

import (
	"fmt"
	"log"
	"net/http"

	"github.com/k1LoW/curlreq"
)

func main() {
	cmd := "curl https://example.com"
	req, err := curlreq.NewRequest(cmd)
	if err != nil {
		log.Fatal(err)
	}
	client := http.DefaultClient
	resp, err := client.Do(req)
	if err != nil {
		log.Fatal(err)
	}
	defer resp.Body.Close()

	fmt.Println(resp.StatusCode)

}
Output:

200

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRequest

func NewRequest(cmd ...string) (*http.Request, error)

NewRequest returns *http.Request created by parsing a curl command.

Types

type Option added in v0.4.0

type Option func(*config) error

func WithWorkingDirectory added in v0.4.0

func WithWorkingDirectory(path string) Option

type Parsed

type Parsed struct {
	URL    *url.URL
	Method string
	Header http.Header
	Body   []byte
}

func Parse

func Parse(cmd ...string) (*Parsed, error)

Parse a curl command.

func (*Parsed) MarshalJSON added in v0.2.0

func (p *Parsed) MarshalJSON() ([]byte, error)

func (*Parsed) Request

func (p *Parsed) Request() (*http.Request, error)

Request returns *http.Request.

type Parser added in v0.4.0

type Parser struct {
	// contains filtered or unexported fields
}

func NewParser added in v0.4.0

func NewParser(opts ...Option) (*Parser, error)

func (*Parser) Parse added in v0.4.0

func (p *Parser) Parse(cmd ...string) (*Parsed, error)

Jump to

Keyboard shortcuts

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