web

package
Version: v0.0.0-...-854ad97 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2021 License: BSD-3-Clause Imports: 15 Imported by: 1

Documentation

Overview

Package web provides functions for interacting with a REST API. It was designed to work with GIN Gogs (https://github.com/G-Node/gogs), a fork of the Gogs git service (https://github.com/gogits/gogs), and therefore only implements requests and assumes responses for working with that particular API. Beyond that, the implementation is relatively general and service agnostic.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloseRes

func CloseRes(b io.ReadCloser)

CloseRes closes a given result buffer (for use with defer).

func DeleteToken

func DeleteToken(srvalias string) error

DeleteToken deletes the token file if it exists (for finalising a logout).

Types

type Client

type Client struct {
	Host string
	UserToken
	// contains filtered or unexported fields
}

Client struct for making requests

func New

func New(host string) *Client

New creates a new client for a given host.

func (*Client) Delete

func (cl *Client) Delete(address string) (*http.Response, error)

Delete sends a DELETE request to address.

func (*Client) Get

func (cl *Client) Get(address string) (*http.Response, error)

Get sends a GET request to address. The address is appended to the client host, so it should be specified without a host prefix.

func (*Client) GetBasicAuth

func (cl *Client) GetBasicAuth(address, username, password string) (*http.Response, error)

GetBasicAuth sends a GET request to address. The username and password are used to perform Basic authentication.

func (*Client) Post

func (cl *Client) Post(address string, data interface{}) (*http.Response, error)

Post sends a POST request to address with the provided data. The address is appended to the client host, so it should be specified without a host prefix.

func (*Client) PostBasicAuth

func (cl *Client) PostBasicAuth(address, username, password string, data interface{}) (*http.Response, error)

PostBasicAuth sends a POST request to address with the provided data. The username and password are used to perform Basic authentication.

type UserToken

type UserToken struct {
	Username string
	Token    string
}

UserToken struct for username and token

func (*UserToken) LoadToken

func (ut *UserToken) LoadToken(srvalias string) error

LoadToken reads the username and auth token from the token file and sets the values in the struct.

func (*UserToken) StoreToken

func (ut *UserToken) StoreToken(srvalias string) error

StoreToken saves the username and auth token to the token file.

Source Files

Jump to

Keyboard shortcuts

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