Skip to content

agung96tm/rajaongkir-go

Repository files navigation

Rajakongkir Go

Go Report Card Codecov Version Release License GoDoc

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.Status { Code, Description }
	// citiesResp.Results []City

	// --------------------------------------
	// 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 :)