http

package module
v0.0.0-...-251de27 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2020 License: MIT Imports: 10 Imported by: 0

README

TinyPHP-Http

package main

import (
	"github.com/kimkit/tinyphp"
	"github.com/kimkit/tinyphp-http"
	"github.com/kimkit/tinyphp/std"
)

func init() {
	http.RegisterHttp()
	http.AddHttp("t3", http.NewClient(3))
}

func main() {
	src := `
$http = get_http("t3")->ok();
$header = new_dict();
$header->set("X-Client", "tinyphp");
$resp = $http->request("GET", "http://baidu.com", "", $header)->ok();
var_dump($resp->status());
var_dump($resp->body());
foreach ($resp->header() as $k => $v) {
    printf("%v: %v\n", $k, $v);
}
var_dump($resp->header("Date"));
    `
	stmts, err := tinyphp.ParseSrc(src)
	if err != nil {
		panic(err)
	}
	store := tinyphp.NewStore(std.Funcs, std.Methods)
	if _, err := tinyphp.RunStmts(stmts, store); err != nil {
		panic(err)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound = fmt.Errorf("not found")
)

Functions

func AddHttp

func AddHttp(name string, client *http.Client)

func GetHttpClient

func GetHttpClient(name string) (*http.Client, error)

func NewClient

func NewClient(timeout int) *http.Client

func RegisterHttp

func RegisterHttp()

Types

type Http

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

func GetHttp

func GetHttp(name string) (*Http, error)

func (*Http) GetClient

func (h *Http) GetClient() *http.Client

func (*Http) Request

func (h *Http) Request(method, url, body string, headers map[string]interface{}) (*Response, error)

func (*Http) TypeName

func (h *Http) TypeName() string

type Response

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

func NewResponse

func NewResponse(statusCode int, body string, headers map[string]interface{}) *Response

func (*Response) GetBody

func (r *Response) GetBody() string

func (*Response) GetHeader

func (r *Response) GetHeader(name string) string

func (*Response) GetHeaders

func (r *Response) GetHeaders() map[string]interface{}

func (*Response) GetStatusCode

func (r *Response) GetStatusCode() int

func (*Response) TypeName

func (r *Response) TypeName() string

Jump to

Keyboard shortcuts

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