curlreq

package module
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2024 License: MIT Imports: 8 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 Parsed

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

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

Jump to

Keyboard shortcuts

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