...

Source file src/golang.conradwood.net/go-easyops/http/http.go

Documentation: golang.conradwood.net/go-easyops/http

     1  /*
     2  make http requests in a safe manner. optionally cache results
     3  */
     4  package http
     5  
     6  import (
     7  	"context"
     8  	"flag"
     9  	"fmt"
    10  	"net/http"
    11  	"time"
    12  )
    13  
    14  var (
    15  	debug = flag.Bool("ge_debug_http", false, "debug http code")
    16  )
    17  
    18  type HTTPIF interface {
    19  	Cookie(name string) *http.Cookie
    20  	Cookies() []*http.Cookie
    21  	Delete(url string, body []byte) *HTTPResponse
    22  	Get(url string) *HTTPResponse
    23  	GetStream(url string) *HTTPResponse
    24  	Head(url string) *HTTPResponse
    25  	Post(url string, body []byte) *HTTPResponse
    26  	Put(url string, body string) *HTTPResponse
    27  	SetHeader(key string, value string)
    28  	SetTimeout(dur time.Duration)
    29  	SetDebug(b bool)
    30  	SetCreds(username, password string)
    31  }
    32  
    33  // use urlcacher for the url (needs ctx to authenticate)
    34  func NewCachingClient(ctx context.Context) HTTPIF {
    35  	if *debug {
    36  		fmt.Printf("[go-easyops] New caching client..\n")
    37  	}
    38  	res := &cHTTP{}
    39  	res.ctx, res.ctx_cancel = context.WithCancel(ctx)
    40  	//	res.ctx = ctx
    41  	return res
    42  }
    43  
    44  // retrieve directly from source
    45  func NewDirectClient() HTTPIF {
    46  	if *debug {
    47  		fmt.Printf("[go-easyops] New direct client..\n")
    48  	}
    49  	return &HTTP{}
    50  }
    51  

View as plain text