httpx

package
v1.6.5-rc10 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	HeaderUserAgent          = "User-Agent"
	HeaderContentType        = "Content-Type"
	HeaderContentDisposition = "Content-Disposition"
	HeaderRequestID          = "X-Request-ID"
	HeaderForwardedFor       = "X-Forwarded-For"
	HeaderRealIP             = "X-Real-IP"
)
View Source
const (
	MIME_OCTET_STREAM      = "application/octet-stream"
	MIME_JSON              = "application/json"
	MIME_XML               = "application/xml"
	MIME_FORM_URLENCODED   = "application/x-www-form-urlencoded"
	MIME_MULTIPART_FORMDAT = "multipart/form-data"
	MIME_PROTOBUF          = "application/x-protobuf"
	MIME_MSGPACK           = "application/x-msgpack"
	MIME_PLAIN_TEXT        = "text/plain"
)

Variables

This section is empty.

Functions

func ClientIP

func ClientIP(r *http.Request) string

func ClientIPByHeaderForwardedFor

func ClientIPByHeaderForwardedFor(headerForwardedFor string) string

ClientIPByHeaderForwardedFor X-Forwarded-For: client, proxy1, proxy2 https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-For

func ClientIPByHeaderRealIP

func ClientIPByHeaderRealIP(headerRealIP string) string

ClientIPByHeaderRealIP X-Forwarded-For: client, proxy1, proxy2 https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-For

func ContextWithStatusCode

func ContextWithStatusCode(ctx context.Context, code int) context.Context

func MaybeWriteHeader

func MaybeWriteHeader(ctx context.Context, w io.Writer, ct string, param map[string]string)

func Metadata

func Metadata(k string, vs ...string) kit.Metadata

func StatusCodeFromContext

func StatusCodeFromContext(ctx context.Context) int

Types

type ApplicationOgg

type ApplicationOgg struct{ bytes.Buffer }
Example
package main

import (
	"fmt"

	"github.com/machinefi/w3bstream/pkg/depends/kit/httptransport/httpx"
)

func main() {
	m := httpx.NewApplicationOgg()
	fmt.Println(m.ContentType())
}
Output:

application/ogg

func NewApplicationOgg

func NewApplicationOgg() *ApplicationOgg

func (ApplicationOgg) ContentType

func (ApplicationOgg) ContentType() string

type ApplicationProtobuf added in v1.0.0

type ApplicationProtobuf struct{ bytes.Buffer }
Example
package main

import (
	"fmt"

	"github.com/machinefi/w3bstream/pkg/depends/kit/httptransport/httpx"
)

func main() {
	m := httpx.NewApplicationProtobuf()
	fmt.Println(m.ContentType())
}
Output:

application/x-protobuf

func NewApplicationProtobuf added in v1.0.0

func NewApplicationProtobuf() *ApplicationProtobuf

func NewApplicationProtobufWith added in v1.0.0

func NewApplicationProtobufWith(msg proto.Message) (*ApplicationProtobuf, error)

func (ApplicationProtobuf) ContentType added in v1.0.0

func (ApplicationProtobuf) ContentType() string

type Attachment

type Attachment struct {
	bytes.Buffer
	// contains filtered or unexported fields
}

func NewAttachment

func NewAttachment(filename string, contentType string) *Attachment

func (*Attachment) ContentType

func (a *Attachment) ContentType() string

func (*Attachment) Meta

func (a *Attachment) Meta() kit.Metadata

type AudioMidi

type AudioMidi struct{ bytes.Buffer }
Example
package main

import (
	"fmt"

	"github.com/machinefi/w3bstream/pkg/depends/kit/httptransport/httpx"
)

func main() {
	m := httpx.NewAudioMidi()
	fmt.Println(m.ContentType())
}
Output:

audio/midi

func NewAudioMidi

func NewAudioMidi() *AudioMidi

func (AudioMidi) ContentType

func (AudioMidi) ContentType() string

type AudioMp3

type AudioMp3 struct{ bytes.Buffer }
Example
package main

import (
	"fmt"

	"github.com/machinefi/w3bstream/pkg/depends/kit/httptransport/httpx"
)

func main() {
	m := httpx.NewAudioMp3()
	fmt.Println(m.ContentType())
}
Output:

audio/mpeg

func NewAudioMp3

func NewAudioMp3() *AudioMp3

func (AudioMp3) ContentType

func (AudioMp3) ContentType() string

type AudioOgg

type AudioOgg struct{ bytes.Buffer }
Example
package main

import (
	"fmt"

	"github.com/machinefi/w3bstream/pkg/depends/kit/httptransport/httpx"
)

func main() {
	m := httpx.NewAudioOgg()
	fmt.Println(m.ContentType())
}
Output:

audio/ogg

func NewAudioOgg

func NewAudioOgg() *AudioOgg

func (AudioOgg) ContentType

func (AudioOgg) ContentType() string

type AudioWave

type AudioWave struct{ bytes.Buffer }
Example
package main

import (
	"fmt"

	"github.com/machinefi/w3bstream/pkg/depends/kit/httptransport/httpx"
)

func main() {
	m := httpx.NewAudioWave()
	fmt.Println(m.ContentType())
}
Output:

audio/wav

func NewAudioWave

func NewAudioWave() *AudioWave

func (AudioWave) ContentType

func (AudioWave) ContentType() string

type AudioWebm

type AudioWebm struct{ bytes.Buffer }
Example
package main

import (
	"fmt"

	"github.com/machinefi/w3bstream/pkg/depends/kit/httptransport/httpx"
)

func main() {
	m := httpx.NewAudioWebm()
	fmt.Println(m.ContentType())
}
Output:

audio/webm

func NewAudioWebm

func NewAudioWebm() *AudioWebm

func (AudioWebm) ContentType

func (AudioWebm) ContentType() string

type CSS

type CSS struct{ bytes.Buffer }
Example
package main

import (
	"fmt"

	"github.com/machinefi/w3bstream/pkg/depends/kit/httptransport/httpx"
)

func main() {
	m := httpx.NewCSS()
	fmt.Println(m.ContentType())
}
Output:

text/css

func NewCSS

func NewCSS() *CSS

func (CSS) ContentType

func (CSS) ContentType() string

type Encode

type Encode func(context.Context, io.Writer, interface{}) error

type HTML

type HTML struct{ bytes.Buffer }
Example
package main

import (
	"fmt"

	"github.com/machinefi/w3bstream/pkg/depends/kit/httptransport/httpx"
)

func main() {
	m := httpx.NewHTML()
	fmt.Println(m.ContentType())
}
Output:

text/html

func NewHTML

func NewHTML() *HTML

func (HTML) ContentType

func (HTML) ContentType() string

type ImageBmp

type ImageBmp struct{ bytes.Buffer }
Example
package main

import (
	"fmt"

	"github.com/machinefi/w3bstream/pkg/depends/kit/httptransport/httpx"
)

func main() {
	m := httpx.NewImageBmp()
	fmt.Println(m.ContentType())
}
Output:

image/bmp

func NewImageBmp

func NewImageBmp() *ImageBmp

func (ImageBmp) ContentType

func (ImageBmp) ContentType() string

type ImageGIF

type ImageGIF struct{ bytes.Buffer }
Example
package main

import (
	"fmt"

	"github.com/machinefi/w3bstream/pkg/depends/kit/httptransport/httpx"
)

func main() {
	m := httpx.NewImageGIF()
	fmt.Println(m.ContentType())
}
Output:

image/gif

func NewImageGIF

func NewImageGIF() *ImageGIF

func (ImageGIF) ContentType

func (ImageGIF) ContentType() string

type ImageJPEG

type ImageJPEG struct{ bytes.Buffer }
Example
package main

import (
	"fmt"

	"github.com/machinefi/w3bstream/pkg/depends/kit/httptransport/httpx"
)

func main() {
	m := httpx.NewImageJPEG()
	fmt.Println(m.ContentType())
}
Output:

image/jpeg

func NewImageJPEG

func NewImageJPEG() *ImageJPEG

func (ImageJPEG) ContentType

func (ImageJPEG) ContentType() string

type ImagePNG

type ImagePNG struct{ bytes.Buffer }
Example
package main

import (
	"fmt"

	"github.com/machinefi/w3bstream/pkg/depends/kit/httptransport/httpx"
)

func main() {
	m := httpx.NewImagePNG()
	fmt.Println(m.ContentType())
}
Output:

image/png

func NewImagePNG

func NewImagePNG() *ImagePNG

func (ImagePNG) ContentType

func (ImagePNG) ContentType() string

type ImageSVG

type ImageSVG struct{ bytes.Buffer }
Example
package main

import (
	"fmt"

	"github.com/machinefi/w3bstream/pkg/depends/kit/httptransport/httpx"
)

func main() {
	m := httpx.NewImageSVG()
	fmt.Println(m.ContentType())
}
Output:

image/svg+xml

func NewImageSVG

func NewImageSVG() *ImageSVG

func (ImageSVG) ContentType

func (ImageSVG) ContentType() string

type ImageWebp

type ImageWebp struct{ bytes.Buffer }
Example
package main

import (
	"fmt"

	"github.com/machinefi/w3bstream/pkg/depends/kit/httptransport/httpx"
)

func main() {
	m := httpx.NewImageWebp()
	fmt.Println(m.ContentType())
}
Output:

image/webp

func NewImageWebp

func NewImageWebp() *ImageWebp

func (ImageWebp) ContentType

func (ImageWebp) ContentType() string

type Method

type Method struct{}

type MethodConnect

type MethodConnect struct{}

func (MethodConnect) Method

func (MethodConnect) Method() string

type MethodDelete

type MethodDelete struct{}

func (MethodDelete) Method

func (MethodDelete) Method() string

type MethodGet

type MethodGet struct{}

func (MethodGet) Method

func (MethodGet) Method() string

type MethodHead

type MethodHead struct{}

func (MethodHead) Method

func (MethodHead) Method() string

type MethodOptions

type MethodOptions struct{}

func (MethodOptions) Method

func (MethodOptions) Method() string

type MethodPatch

type MethodPatch struct{}

func (MethodPatch) Method

func (MethodPatch) Method() string

type MethodPost

type MethodPost struct{}

func (MethodPost) Method

func (MethodPost) Method() string

type MethodPut

type MethodPut struct{}

func (MethodPut) Method

func (MethodPut) Method() string

type MethodTrace

type MethodTrace struct{}

func (MethodTrace) Method

func (MethodTrace) Method() string

type Plain

type Plain struct{ bytes.Buffer }
Example
package main

import (
	"fmt"

	"github.com/machinefi/w3bstream/pkg/depends/kit/httptransport/httpx"
)

func main() {
	m := httpx.NewPlain()
	fmt.Println(m.ContentType())
}
Output:

text/plain

func NewPlain

func NewPlain() *Plain

func (Plain) ContentType

func (Plain) ContentType() string

type RedirectDescriber

type RedirectDescriber interface {
	WithStatusCode
	Location() *url.URL
}

type RequestInfo

type RequestInfo interface {
	Context() context.Context
	Values(in string, name string) []string
	Header() http.Header
	Body() io.ReadCloser
}

func NewRequestInfo

func NewRequestInfo(r *http.Request) RequestInfo

type ResolveEncode

type ResolveEncode func(*Response) (Encode, error)

type Response

type Response struct {
	Value       interface{} // Value of body
	Meta        kit.Metadata
	Cookies     []*http.Cookie
	Location    *url.URL
	ContentType string
	StatusCode  int
}

func ResponseFrom

func ResponseFrom(v interface{}) *Response

func (*Response) Error

func (r *Response) Error() string

func (*Response) Unwrap

func (r *Response) Unwrap() error

func (*Response) WriteTo

func (r *Response) WriteTo(rw http.ResponseWriter, req *http.Request, resolve ResolveEncode) error

type ResponseWrapper

type ResponseWrapper func(v interface{}) *Response

func Compose

func Compose(rws ...ResponseWrapper) ResponseWrapper

func WrapContentType

func WrapContentType(ct string) ResponseWrapper

func WrapCookies

func WrapCookies(cookies ...*http.Cookie) ResponseWrapper

func WrapMeta

func WrapMeta(metas ...kit.Metadata) ResponseWrapper

func WrapSchema

func WrapSchema(s interface{}) ResponseWrapper

func WrapStatusCode

func WrapStatusCode(statusCode int) ResponseWrapper

type ResponseWriteError

type ResponseWriteError interface {
	WriteError(err error) (int, error)
}

type StatusFound

type StatusFound struct{ *Response }
Example
package main

import (
	"fmt"
	"net/url"

	"github.com/machinefi/w3bstream/pkg/depends/kit/httptransport/httpx"
)

func main() {
	m := httpx.RedirectWithStatusFound(&(url.URL{
		Path: "/test",
	}))
	fmt.Println(m.StatusCode())
	fmt.Println(m.Location())
}
Output:

302
/test

func RedirectWithStatusFound

func RedirectWithStatusFound(u *url.URL) *StatusFound

func (StatusFound) Location

func (r StatusFound) Location() *url.URL

func (StatusFound) StatusCode

func (StatusFound) StatusCode() int

type StatusMovedPermanently

type StatusMovedPermanently struct{ *Response }
Example
package main

import (
	"fmt"
	"net/url"

	"github.com/machinefi/w3bstream/pkg/depends/kit/httptransport/httpx"
)

func main() {
	m := httpx.RedirectWithStatusMovedPermanently(&(url.URL{
		Path: "/test",
	}))
	fmt.Println(m.StatusCode())
	fmt.Println(m.Location())
}
Output:

301
/test

func RedirectWithStatusMovedPermanently

func RedirectWithStatusMovedPermanently(u *url.URL) *StatusMovedPermanently

func (StatusMovedPermanently) Location

func (r StatusMovedPermanently) Location() *url.URL

func (StatusMovedPermanently) StatusCode

func (StatusMovedPermanently) StatusCode() int

type StatusMultipleChoices

type StatusMultipleChoices struct{ *Response }
Example
package main

import (
	"fmt"
	"net/url"

	"github.com/machinefi/w3bstream/pkg/depends/kit/httptransport/httpx"
)

func main() {
	m := httpx.RedirectWithStatusMultipleChoices(&(url.URL{
		Path: "/test",
	}))
	fmt.Println(m.StatusCode())
	fmt.Println(m.Location())
}
Output:

300
/test

func RedirectWithStatusMultipleChoices

func RedirectWithStatusMultipleChoices(u *url.URL) *StatusMultipleChoices

func (StatusMultipleChoices) Location

func (r StatusMultipleChoices) Location() *url.URL

func (StatusMultipleChoices) StatusCode

func (StatusMultipleChoices) StatusCode() int

type StatusNotModified

type StatusNotModified struct{ *Response }
Example
package main

import (
	"fmt"
	"net/url"

	"github.com/machinefi/w3bstream/pkg/depends/kit/httptransport/httpx"
)

func main() {
	m := httpx.RedirectWithStatusNotModified(&(url.URL{
		Path: "/test",
	}))
	fmt.Println(m.StatusCode())
	fmt.Println(m.Location())
}
Output:

304
/test

func RedirectWithStatusNotModified

func RedirectWithStatusNotModified(u *url.URL) *StatusNotModified

func (StatusNotModified) Location

func (r StatusNotModified) Location() *url.URL

func (StatusNotModified) StatusCode

func (StatusNotModified) StatusCode() int

type StatusPermanentRedirect

type StatusPermanentRedirect struct{ *Response }
Example
package main

import (
	"fmt"
	"net/url"

	"github.com/machinefi/w3bstream/pkg/depends/kit/httptransport/httpx"
)

func main() {
	m := httpx.RedirectWithStatusPermanentRedirect(&(url.URL{
		Path: "/test",
	}))
	fmt.Println(m.StatusCode())
	fmt.Println(m.Location())
}
Output:

308
/test

func RedirectWithStatusPermanentRedirect

func RedirectWithStatusPermanentRedirect(u *url.URL) *StatusPermanentRedirect

func (StatusPermanentRedirect) Location

func (r StatusPermanentRedirect) Location() *url.URL

func (StatusPermanentRedirect) StatusCode

func (StatusPermanentRedirect) StatusCode() int

type StatusSeeOther

type StatusSeeOther struct{ *Response }
Example
package main

import (
	"fmt"
	"net/url"

	"github.com/machinefi/w3bstream/pkg/depends/kit/httptransport/httpx"
)

func main() {
	m := httpx.RedirectWithStatusSeeOther(&(url.URL{
		Path: "/test",
	}))
	fmt.Println(m.StatusCode())
	fmt.Println(m.Location())
}
Output:

303
/test

func RedirectWithStatusSeeOther

func RedirectWithStatusSeeOther(u *url.URL) *StatusSeeOther

func (StatusSeeOther) Location

func (r StatusSeeOther) Location() *url.URL

func (StatusSeeOther) StatusCode

func (StatusSeeOther) StatusCode() int

type StatusTemporaryRedirect

type StatusTemporaryRedirect struct{ *Response }
Example
package main

import (
	"fmt"
	"net/url"

	"github.com/machinefi/w3bstream/pkg/depends/kit/httptransport/httpx"
)

func main() {
	m := httpx.RedirectWithStatusTemporaryRedirect(&(url.URL{
		Path: "/test",
	}))
	fmt.Println(m.StatusCode())
	fmt.Println(m.Location())
}
Output:

307
/test

func RedirectWithStatusTemporaryRedirect

func RedirectWithStatusTemporaryRedirect(u *url.URL) *StatusTemporaryRedirect

func (StatusTemporaryRedirect) Location

func (r StatusTemporaryRedirect) Location() *url.URL

func (StatusTemporaryRedirect) StatusCode

func (StatusTemporaryRedirect) StatusCode() int

type StatusUseProxy

type StatusUseProxy struct{ *Response }
Example
package main

import (
	"fmt"
	"net/url"

	"github.com/machinefi/w3bstream/pkg/depends/kit/httptransport/httpx"
)

func main() {
	m := httpx.RedirectWithStatusUseProxy(&(url.URL{
		Path: "/test",
	}))
	fmt.Println(m.StatusCode())
	fmt.Println(m.Location())
}
Output:

305
/test

func RedirectWithStatusUseProxy

func RedirectWithStatusUseProxy(u *url.URL) *StatusUseProxy

func (StatusUseProxy) Location

func (r StatusUseProxy) Location() *url.URL

func (StatusUseProxy) StatusCode

func (StatusUseProxy) StatusCode() int

type Upgrader

type Upgrader interface {
	Upgrade(http.ResponseWriter, *http.Request) error
}

type VideoOgg

type VideoOgg struct{ bytes.Buffer }
Example
package main

import (
	"fmt"

	"github.com/machinefi/w3bstream/pkg/depends/kit/httptransport/httpx"
)

func main() {
	m := httpx.NewVideoOgg()
	fmt.Println(m.ContentType())
}
Output:

video/ogg

func NewVideoOgg

func NewVideoOgg() *VideoOgg

func (VideoOgg) ContentType

func (VideoOgg) ContentType() string

type VideoWebm

type VideoWebm struct{ bytes.Buffer }
Example
package main

import (
	"fmt"

	"github.com/machinefi/w3bstream/pkg/depends/kit/httptransport/httpx"
)

func main() {
	m := httpx.NewVideoWebm()
	fmt.Println(m.ContentType())
}
Output:

video/webm

func NewVideoWebm

func NewVideoWebm() *VideoWebm

func (VideoWebm) ContentType

func (VideoWebm) ContentType() string

type WithContentType

type WithContentType interface {
	ContentType() string
}

type WithCookies

type WithCookies interface {
	Cookies() []*http.Cookie
}

type WithFromRequestInfo

type WithFromRequestInfo interface {
	FromRequestInfo(ri RequestInfo) error
}

type WithHeader

type WithHeader interface {
	Header() http.Header
}

type WithStatusCode

type WithStatusCode interface {
	StatusCode() int
}

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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