networkutil

package module
v1.0.10 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2021 License: MIT Imports: 9 Imported by: 7

README

network-util

Go network util package

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CorsConfig = cors.New(cors.Options{
	AllowedOrigins: []string{
		"https://hello-slide.jp",
		"https://hello-slide.com",
		"https://hello-slide.net",
		"http://localhost:3000",
	},
	AllowCredentials: true,
})

Functions

func ErrorResponse

func ErrorResponse(w http.ResponseWriter, statusCode int, err error)

func ErrorStatus

func ErrorStatus(w http.ResponseWriter)

func GetFromKey

func GetFromKey(key string, w http.ResponseWriter, req *http.Request) (string, error)

func GetHeader

func GetHeader(w http.ResponseWriter, req *http.Request) (map[string]string, error)

func PickValue

func PickValue(key string, data map[string]string, w http.ResponseWriter) (string, error)

Types

type CookieOperation added in v1.0.4

type CookieOperation struct {
	Path     string
	Domain   string
	Secure   bool
	HttpOnly bool
}

func NewCookieOp added in v1.0.4

func NewCookieOp(domain string) *CookieOperation

func (*CookieOperation) Delete added in v1.0.4

func (c *CookieOperation) Delete(w http.ResponseWriter, req *http.Request, name string) error

Delete cookie

Arguments:

w {http.ResponseWriter} - http writer.
req {http.Request} - http request.

name {string} - cookie key.

func (*CookieOperation) Get added in v1.0.4

func (c *CookieOperation) Get(req *http.Request, name string) (string, error)

Get cookie.

Arguments:

req {http.Request} - http request.
name {string} - cookie key.

Retruns:

{string} - cookie value.

func (*CookieOperation) Set added in v1.0.4

func (c *CookieOperation) Set(w http.ResponseWriter, name string, value string, exp int)

Set cookie.

Arguments:

w {http.ResponseWriter} - http writer.
name {string} - cookie key.
value {string} - cookie value.
exp {int} - date of expiry. It is an hourly unit.

type TokenOperation added in v1.0.4

type TokenOperation struct {
	CookieOp CookieOperation
}

func NewTokenOp added in v1.0.4

func NewTokenOp(apiUrl string) (*TokenOperation, error)

Create tokenOp.

Arguments;

apiUrl {string} - URL of the API you are using.

func (*TokenOperation) DeleteToken added in v1.0.4

func (t *TokenOperation) DeleteToken(w http.ResponseWriter, r *http.Request) error

Delete session and refresh tokens.

Arguments:

w {http.ResponseWriter} - http writer.
r {*http.Request} - http requests.

func (*TokenOperation) GetRefreshToken added in v1.0.4

func (t *TokenOperation) GetRefreshToken(r *http.Request) (string, error)

Get the refresh token.

Arguments:

r {*http.Request} - http requests.

Returns:

{string} - refresh token.

func (*TokenOperation) GetSessionToken added in v1.0.4

func (t *TokenOperation) GetSessionToken(r *http.Request) (string, error)

Get the session token.

Arguments:

r {*http.Request} - http requests.

Returns:

{string} - session token.

func (*TokenOperation) SetRefreshToken added in v1.0.4

func (t *TokenOperation) SetRefreshToken(w http.ResponseWriter, refreshToken string)

Set the refresh token.

Arguments:

w {http.ResponseWriter} - http writer.
refreshToken {string} - refresh token.

func (*TokenOperation) SetSessionToken added in v1.0.4

func (t *TokenOperation) SetSessionToken(w http.ResponseWriter, sessionToken string)

Set the session token.

Arguments:

w {http.ResponseWriter} - http writer.
sessionToken {string} - session token.

Jump to

Keyboard shortcuts

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