http

package
v1.23.1 Latest Latest
Warning

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

Go to latest
Published: May 2, 2023 License: Apache-2.0 Imports: 15 Imported by: 3

README

Http storage

This package defines http base storage

Usage
afs.Service

    ctx := context.Background()
    service := afs.New()
    service.Copy()
    
    reader, err := service.DownloadWithURL(ctx, URL)
    err := service.Create(ctx, useCase.URL, 0744, false, reader)
    err := service.Upload(ctx, useCase.URL, 0744, reader)
    err := service.Delete(ctx, URL)
Options
Http Client Provider

    ctx := context.Background()
    var clientProvider = func(baseURL string, options ...storage.Option) (*http.Client, error) {
        return http.DefaultClient, nil 
    }
    service := http.New(clientProvider)
    reader, err := service.DownloadWithURL(ctx, URL)
    err := service.Delete(ctx, URL, clientProvider)

Basic Auth

    ctx := context.Background()
    authProvider :=  option.NewBasicAuth("user", "password")
    service := http.New()
    reader, err := service.DownloadWithURL(ctx, URL, authProvider)
Custom Header

    ctx := context.Background()
    header := htttp.Header{}
    header.Set("Set-Cookie", "id=a3fWa; Expires=Wed, 21 Oct 2035 07:28:00 GMT; Secure; HttpOnly")
    reader, err := manager.DownloadWithURL(ctx, URL, header)
    

Response
    ctx := context.Background()
    response := &http.Response{}
    service := http.New()
    reader, err := service.DownloadWithURL(ctx, URL, response)
    err := service.Create(ctx, useCase.URL, 0744, false, reader, response)
    err := service.Upload(ctx, useCase.URL, 0744, reader, response)
    err := service.Delete(ctx, URL. response)
   

Documentation

Overview

Package http defines simple http based storage operation

Index

Constants

View Source
const Scheme = "http"

Scheme represents http url scheme

View Source
const SecureScheme = "https"

SecureScheme represents secure http url scheme

Variables

This section is empty.

Functions

func CloseIdleConnections

func CloseIdleConnections(client interface{})

CloseIdleConnections closes iddle connections

func HeaderTime

func HeaderTime(header http.Header, key string, defaultValue time.Time) time.Time

HeaderTime returns time for header key

func IsStatusOK

func IsStatusOK(response *http.Response) bool

IsStatusOK returns true if status is 2xxx

func New

func New(options ...storage.Option) storage.Manager

New creates HTTP manager

func ParseHTTPDate

func ParseHTTPDate(value string) (result time.Time, err error)

ParseHTTPDate parses date assigned

func Provider

func Provider(options ...storage.Option) (storage.Manager, error)

Provider returns a http manager

Types

type ClientProvider

type ClientProvider func(baseURL string, options ...storage.Option) (*http.Client, error)

ClientProvider represents clinet provider option

Jump to

Keyboard shortcuts

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