rajaongkir_go

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2023 License: MIT Imports: 9 Imported by: 0

README

Rajakongkir Go

Installation

go get -u github.com/agung96tm/rajaongkir-go

Usage

package main

import (
	"fmt"
	ongkir "github.com/agung96tm/rajaongkir-go"
)

func main() {
	api := ongkir.NewAPI(ongkir.NewConfig(
		"key",
		ongkir.AccountStarter,
	))

	// --------------------------------------
	// Provinces
	// --------------------------------------
	provResp, err := api.GetProvinces(nil)
	//provResp, err := api.GetProvinces(ongkir.ProvinceParams{ID: "1"})

	if err != nil {
		panic(err)
	}
	
	fmt.Println(provResp.Results)
	// provResp.Status { Code, Description }
	// provResp.Results []Province

	// --------------------------------------
	// Cities
	// --------------------------------------
	citiesResp, err := api.GetCities(nil)
	//citiesResp, err := api.GetCities(ongkir.CityParams{ID: "1", ProvinceID: "1"})

	if err != nil {
		panic(err)
	}
	
	fmt.Println(citiesResp.Results)
	// citiesResp.Results []City
	// citiesResp.Status { Code, Description }

	// --------------------------------------
	// Cost
	// -------------------------------------- 
	costResp, err := app.GetCost(&ongkir.CostParams{
		Courier:     JNE, // CouriersParams(JNE),
		Origin:      "501",
		Destination: "114",
		Weight:      1,
	})
	
	fmt.Println(costResp.Results)
	// costResp.Results []Courier
	// costResp.Results[0].Courier {Code, Name, Costs}
}

Contributors

Hey you! Interest become contributor? Then make issue or PR :)

Documentation

Index

Constants

View Source
const (
	StarterAPIUrl = "https://api.rajaongkir.com/starter"
	BasicAPIUrl   = "https://api.rajaongkir.com/basic"
	ProAPIUrl     = "https://pro.rajaongkir.com/api"
)
View Source
const AccountBasic = "basic"
View Source
const AccountPro = "pro"
View Source
const AccountStarter = "starter"
View Source
const ESL = "esl"
View Source
const JNE = "jne"
View Source
const PCP = "pcp"
View Source
const POS = "pos"
View Source
const RPX = "rpx"
View Source
const TIKI = "tiki"

Variables

This section is empty.

Functions

func CourierParams

func CourierParams(couriers ...string) string

func GetApiURL

func GetApiURL(accountType string) string

Types

type API

type API struct {
	// contains filtered or unexported fields
}

func NewAPI

func NewAPI(config Config) API

func (API) GetCities

func (a API) GetCities(opts *CityParams) (respCities ResponseCities, err error)

func (API) GetCost

func (a API) GetCost(opts *CostParams) (respCost ResponseCost, err error)

func (API) GetProvinces

func (a API) GetProvinces(opts *ProvinceParams) (respProv ResponseProvinces, err error)

type City

type City struct {
	ID         string `json:"city_id"`
	City       string `json:"city_name"`
	ProvinceID string `json:"province_id"`
	Province   string `json:"province"`
	PostalCode string `json:"postal_code"`
}

type CityParams

type CityParams struct {
	ID         string `query:"id" json:"id"`
	ProvinceID string `query:"province" json:"province"`
}

type Config

type Config struct {
	BaseUrl     string
	Header      map[string]string
	AccountKey  string
	AccountType string
}

func NewConfig

func NewConfig(accountKey string, accountType string) Config

type Cost

type Cost struct {
	Value string `json:"value"`
	Etd   string `json:"etd"`
	Note  string `json:"note"`
}

type CostParams

type CostParams struct {
	Origin      string `query:"origin" json:"origin"`
	Destination string `query:"destination" json:"destination"`
	Weight      int    `query:"weight" json:"weight"`
	Courier     string `query:"courier" json:"courier"`
}

type Courier

type Courier struct {
	Code  string        `json:"code"`
	Name  string        `json:"name"`
	Costs []CourierCost `json:"costs"`
}

type CourierCost

type CourierCost struct {
	Service     string `json:"service"`
	Description string `json:"description"`
	Cost        []Cost `json:"cost"`
}

type Province

type Province struct {
	ID       string `json:"province_id"`
	Province string `json:"province"`
}

type ProvinceParams

type ProvinceParams struct {
	ID string `query:"id" json:"id"`
}

type ResponseBase

type ResponseBase[T interface{}, P interface{}] struct {
	Query   P              `json:"query"`
	Status  ResponseStatus `json:"status"`
	Results []T            `json:"results"`
}

func (*ResponseBase[T, P]) StatusValid

func (b *ResponseBase[T, P]) StatusValid() error

func (*ResponseBase[T, P]) Unmarshal

func (b *ResponseBase[T, P]) Unmarshal(v []byte) error

type ResponseCities

type ResponseCities struct {
	ResponseBase[City, CityParams]
}

type ResponseCost

type ResponseCost struct {
	ResponseBase[Courier, CostParams]
}

type ResponseProvinces

type ResponseProvinces struct {
	ResponseBase[Province, ProvinceParams]
}

type ResponseStatus

type ResponseStatus struct {
	Code        int    `json:"code"`
	Description string `json:"description"`
}

Jump to

Keyboard shortcuts

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