go-langext

module
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2024 License: Apache-2.0

README

Go Extension functions

go-langext is a collection of complementary functions which is missing in Go library.

How to install

go get github.com/rookiecj/go-langext

How to use

Here is httpx example:

package main

import (
	"fmt"
	"github.com/rookiecj/go-langext/httpx"
)

type testPost struct {
	UserId int    `json:"userId"`
	Id     int    `json:"id"`
	Title  string `json:"title"`
	Body   string `json:"body"`
}

var testPostUrl = "https://jsonplaceholder.typicode.com"

func main() {
    client := httpx.NewClient()

	newPost := testPost{
		UserId: 1,
		Title:  "New title",
		Body:   "New Body",
	}

	if res, err := client.Post(testPostUrl,
		httpx.WithPath("/posts"),
		httpx.WithJsonObject(newPost),
	); err == nil {
		defer res.Close()

		var resPost testPost
		if err := res.Unmarshal(&resPost); err == nil {
			fmt.Printf("res: %v\n", resPost)
		}
	}
}

Extensions

There are two extentions:

  • lang extensions
  • http extensions
lang extensions
  • container: priority queue
  • container: sorted map
  • container: set, sorted set
http extensions
  • NewClient http client with option
  • BodyParser Http response body parser

Todo

  • http response adapter for go-stream

Directories

Path Synopsis
example
ds

Jump to

Keyboard shortcuts

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