http_methods_golang

package module
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2022 License: MIT Imports: 7 Imported by: 1

README

http_method_golang

http_methods_golang is a tiny wrapper for implementing HTTP request methods with Golang, and designed for reuse in every projects which don't have to implement those METHODS, when a simple communication is in need.

Methods

 HTTP Protocol defined serveal request methods for gaining data and contents using Network.

METHOD STATUS
GET
POST
HEAD --
PUT
DELETE
CONNECT --
OPTIONS --
TRACE --
PATCH --
OPERATE STATUS
READ FILE
WRITE FILE

Install

go get github.com/kwangsing3/http_methods_golang

Usage

  • GET

  1. Would return HTML file if request target is website.
  2. Would return bytes if request a data.
//GET: To get data from GET method, need to wait for respone
//<url>: request address.
func GET(url string) ([]byte, error)
  • POST

  1. Mostly use for encrypt request or requested using <form>.
  2. May using for change server status or special request (Depends on the design).
//POST: To get data from POST method, need to wait for respone
//<url>: request address.
//<query>: The query you want to do, mostly are json, but still depends on the server you request.
func POST(url string, query []byte) ([]byte, error) 
  • DELETE

//DELETE: http Delete method request
func DELETE(url string) ([]byte, error) 
  • PUT

//PUT: http Delete method request
func PUT(url string, content string) ([]byte, error) 

Example

package main

import (
	"encoding/json"
	"fmt"
	HMG "github.com/kwangsing3/http_methods_golang"
)

func main() {

	/***GET request***/
	dataGET, errG := HMG.GET("https://example.com")
	if errG != nil {
		fmt.Println(errG.Error())
	} 

	fmt.Println(string(dataGET))
	/*** POST request***/
	query := struct {
		Msg string
	}{
		Msg: `New Message`, //query Struct depends on the server you request.
	}
	bytequery, _ := json.Marshal(query)
	dataPOST, errP := HMG.POST("https://example.com", bytequery)
	if errP != nil {
		fmt.Println(errP.Error())
	} 

	fmt.Println(string(dataPOST))
    return
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DELETE added in v0.3.0

func DELETE(url string, header map[string]string) ([]byte, error)

DELETE: http Delete method request

func GET

func GET(url string, header map[string]string) ([]byte, error)

GET: To get data from GET method, need to wait for respone <url>: request address.

func POST

func POST(url string, header map[string]string, query []byte) ([]byte, error)

POST: To get data from POST method, need to wait for respone <url>: request address. <query>: The query you want to do, mostly are json, depends on the server you request.

func PUT added in v0.3.0

func PUT(url string, header map[string]string, content string) ([]byte, error)

PUT: http Delete method request

func ReadFile added in v0.3.0

func ReadFile(inputPath string) ([]byte, error)

ReadFile: Standard Read file operate. <return> []byte.

func WriteFile added in v0.3.0

func WriteFile(inputPath string, data []byte) error

WriteFile:

Types

This section is empty.

Jump to

Keyboard shortcuts

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