restapi

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2025 License: MIT Imports: 8 Imported by: 1

README

go-restapi Paypal donate

A simple Golang REST api library.

Table Of Content
Features
  • API action
    • Do
    • Get
    • Del
    • Patch
    • Post
    • Put
api.go
func (t *Api) New(property *Property) *Api
func New(property *Property) *Api func (t *Api) Body() *string
func (t *Api) Err() *string
func (t *Api) Ok() bool
func (t *Api) Output() *string
func (t *Api) Do() *Api
func (t *Api) Get() *Api
func (t *Api) Del() *Api
func (t *Api) Patch() *Api
func (t *Api) Post() *Api
func (t *Api) Put() *Api
func (t *Api) SetGet() *Api
func (t *Api) SetDel() *Api
func (t *Api) SetPatch() *Api
func (t *Api) SetPost() *Api
func (t *Api) SetPut() *Api
func (t *Api) ProcessOutput() *Api
func (t *Api) ProcessOutputError() *Api
func (t *Api) ProcessError() *Api
Pro
  • Easy to extend
  • Small size
Doc
Used By Project
Repository
Contributors
Change Log
  • v1.0.0
    • Feature complete
  • v1.0.1
License

The MIT License (MIT)

Copyright © 2025 John, Sing Dao, Siu john.sd.siu@gmail.com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Documentation

Overview

A simple Golang REST api library.

Index

Constants

View Source
const (
	Version = "v1.0.1"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Api

type Api struct {
	*Property

	Req *Req `json:"Req,omitempty"`
	Res *Res `json:"Res,omitempty"`
	// contains filtered or unexported fields
}

Api

func New

func New(property *Property) *Api

Setup a *Api

func (*Api) Body

func (t *Api) Body() *string

Return Res.Body

func (*Api) Del

func (t *Api) Del() *Api

Api Del action wrapper

func (*Api) Do

func (t *Api) Do() *Api

Execute http request using info in Api.Req. Then put response info in Api.Res.

Api.Info, if not nil, will be
		- auto marshal for send other than "GET"
		- auto unmarshal from http response body

func (*Api) Err

func (t *Api) Err() *string

Return Res.Err

func (*Api) Get

func (t *Api) Get() *Api

Api Get action wrapper

func (*Api) New

func (t *Api) New(property *Property) *Api

Setup a *Api

func (*Api) Ok

func (t *Api) Ok() bool

Return Res.Ok()

func (*Api) Output

func (t *Api) Output() *string

Return Res.Output

func (*Api) Patch

func (t *Api) Patch() *Api

Api Patch action wrapper

func (*Api) Post

func (t *Api) Post() *Api

Api Post action wrapper

func (*Api) ProcessError

func (t *Api) ProcessError() *Api

Print HTTP Body Err into string pointer

func (*Api) ProcessOutput

func (t *Api) ProcessOutput() *Api

Print HTTP Body into string pointer

func (*Api) ProcessOutputError

func (t *Api) ProcessOutputError() *Api

Print HTTP Body into string pointer

func (*Api) Put

func (t *Api) Put() *Api

Api Put action wrapper

func (*Api) SetDel

func (t *Api) SetDel() *Api

Api set http Del

func (*Api) SetGet

func (t *Api) SetGet() *Api

func (*Api) SetPatch

func (t *Api) SetPatch() *Api

Api set http Patch

func (*Api) SetPost

func (t *Api) SetPost() *Api

Api set http Post

func (*Api) SetPut

func (t *Api) SetPut() *Api

Api set http Put

type Err

type Err struct {
	Errors  string `json:"Errors,omitempty"` // Used by Gitea
	Message string `json:"Message"`
	Status  string `json:"Status,omitempty"` // Used by Github
}

Github uses message and status. Gitea uses message and errors.

func (*Err) String

func (t *Err) String() string

func (*Err) StringP

func (t *Err) StringP() *string

type IInfo

type IInfo interface {
	StringP() *string
	String() string
}

Api structures interface

type Property

type Property struct {
	Debug      bool
	EntryPoint string
	Info       IInfo
	Method     string
	SkipVerify bool
}

type Req

type Req struct {
	EntryPoint string       `json:"Entrypoint"` // Api base url
	Endpoint   string       `json:"Endpoint"`   // Api endpoint
	Token      string       `json:"Token"`      // Api auth token
	Header     *http.Header `json:"Header"`     // Http request header
	UrlVal     *url.Values  `json:"UrlVal"`     // Api url values
	Data       string       `json:"Data"`       // Json marshaled Info
}

GitApi http input structure

func (*Req) New

func (t *Req) New(entryPoint string) *Req

func (*Req) UrlValInit

func (t *Req) UrlValInit() *Req

Setup empty API url values

type Res

type Res struct {
	Body   *[]byte      `json:"Body"`
	Err    string       `json:"Err"`
	Header *http.Header `json:"Header"` // Http response header
	Output *string      `json:"Output"` // Api response body in string
	Status string       `json:"Status"` // Http response status
	Url    *url.URL     `json:"Url"`    // In.Uri + In.Endpoint
}

GitApi http output structure

func (*Res) New

func (t *Res) New() *Res

func (*Res) Ok

func (t *Res) Ok() bool

Check response status == 2xx

Jump to

Keyboard shortcuts

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