Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Go Lint fixes and GitHub actions added for Test, Coverage and Golint #27

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 39 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Go
on: [ push ]

jobs:
test:
strategy:
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
go: [ 1.13, 1.14, 1.15, 1.16 ]

name: ${{ matrix.os }} @ Go ${{ matrix.go }}
runs-on: ${{ matrix.os }}
steps:
- name: Set up Go ${{ matrix.go }}
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go }}

- name: Set GOPATH and PATH
run: |
echo "GOPATH=$(dirname $GITHUB_WORKSPACE)" >> $GITHUB_ENV
echo "$(dirname $GITHUB_WORKSPACE)/bin" >> $GITHUB_PATH
shell: bash

- name: Checkout Code
uses: actions/checkout@v2
with:
ref: ${{ github.ref }}

- name: Install Dependencies
run: |
go get -v -t -d ./...
go get -v golang.org/x/lint/golint

- name: Run Tests
run: go test -race --cover --covermode=atomic ./...

- name: Lint Check
run: golint -set_exit_status ./...
2 changes: 1 addition & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func NewClient(key string, secret string) *Client {
httpClient := &http.Client{Timeout: requests.TIMEOUT * time.Second}
Request = &requests.Request{Auth: auth, HTTPClient: httpClient,
Version: getVersion(), SDKName: getSDKName(),
BaseURL: constants.BASE_URL}
BaseURL: constants.BaseURL}

addon := resources.Addon{Request: Request}
card := resources.Card{Request: Request}
Expand Down
9 changes: 6 additions & 3 deletions constants/error_code.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package constants

const (
BAD_REQUEST_ERROR = "BAD_REQUEST_ERROR"
GATEWAY_ERROR = "GATEWAY_ERROR"
SERVER_ERROR = "SERVER_ERROR"
//BadRequestError ...
BadRequestError = "BadRequestError"
//GatewayError ...
GatewayError = "GatewayError"
//ServerError ...
ServerError = "ServerError"
)
8 changes: 4 additions & 4 deletions constants/http_status_code.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package constants
import "net/http"

const (
//HTTP_STATUS_OK ...
HTTP_STATUS_OK = http.StatusOK
//HTTP_STATUS_REDIRECT ...
HTTP_STATUS_REDIRECT = http.StatusMultipleChoices
//HTTPStatusOk ...
HTTPStatusOk = http.StatusOK
//HTTPStatusRedirect ...
HTTPStatusRedirect = http.StatusMultipleChoices
)
52 changes: 26 additions & 26 deletions constants/url.go
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
package constants

const (
//BASE_URL ... base api url
BASE_URL = "https://api.razorpay.com/v1"
//ORDER_URL ...orders api base path
ORDER_URL = "/orders"
//INVOICE_URL ...invoices api base path
INVOICE_URL = "/invoices"
//PAYMENT_URL ...payments api base pth
PAYMENT_URL = "/payments"
//PaymentLink_URL ...payments link api base pth
PaymentLink_URL = "/payment_links"
//REFUND_URL ...refunds api base path
REFUND_URL = "/refunds"
//CARD_URL ...cards api base path
CARD_URL = "/cards"
//CUSTOMER_URL ...customers api base path
CUSTOMER_URL = "/customers"
//ADDON_URL ...addon api base path
ADDON_URL = "/addons"
//TRANSFER_URL ...transfers api base path
TRANSFER_URL = "/transfers"
//VIRTUAL_ACCOUNT_URL ...virtual accounts base path
VIRTUAL_ACCOUNT_URL = "/virtual_accounts"
//SUBSCRIPTION_URL ... subscriptions base path
SUBSCRIPTION_URL = "/subscriptions"
//PLAN_URL ... plan api base path
PLAN_URL = "/plans"
//BaseURL ... base api url
BaseURL = "https://api.razorpay.com/v1"
//OrderURL ...orders api base path
OrderURL = "/orders"
//InvoiceURL ...invoices api base path
InvoiceURL = "/invoices"
//PaymentURL ...payments api base pth
PaymentURL = "/payments"
//PaymentLinkURL ...payments link api base pth
PaymentLinkURL = "/payment_links"
//RefundURL ...refunds api base path
RefundURL = "/refunds"
//CardURL ...cards api base path
CardURL = "/cards"
//CustomerURL ...customers api base path
CustomerURL = "/customers"
//AddonURL ...addon api base path
AddonURL = "/addons"
//TransferURL ...transfers api base path
TransferURL = "/transfers"
//VirtualAccountURL ...virtual accounts base path
VirtualAccountURL = "/virtual_accounts"
//SubscriptionURL ...subscriptions base path
SubscriptionURL = "/subscriptions"
//PlanURL ...plan api base path
PlanURL = "/plans"
)
10 changes: 5 additions & 5 deletions requests/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ func (request *Request) doRequestResponse(req *http.Request) (map[string]interfa
if err != nil {
return nil, err
}
if response.StatusCode >= constants.HTTP_STATUS_OK &&
response.StatusCode < constants.HTTP_STATUS_REDIRECT {
if response.StatusCode >= constants.HTTPStatusOk &&
response.StatusCode < constants.HTTPStatusRedirect {
return processResponse(response)
}

Expand All @@ -121,11 +121,11 @@ func (request *Request) doRequestResponse(req *http.Request) (map[string]interfa
errorData := jsonResponse.ErrorData

switch errorData.InternalErrorCode {
case constants.SERVER_ERROR:
case constants.ServerError:
return nil, &errors.ServerError{Message: errorData.Description}
case constants.GATEWAY_ERROR:
case constants.GatewayError:
return nil, &errors.GatewayError{Message: errorData.Description}
case constants.BAD_REQUEST_ERROR:
case constants.BadRequestError:
default:
return nil, &errors.BadRequestError{Message: errorData.Description}
}
Expand Down
4 changes: 2 additions & 2 deletions resources/addon.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ type Addon struct {

// Fetch fetches addon having the given addonID.
func (addon *Addon) Fetch(addonID string, queryParams map[string]interface{}, extraHeaders map[string]string) (map[string]interface{}, error) {
url := fmt.Sprintf("%s/%s", constants.ADDON_URL, addonID)
url := fmt.Sprintf("%s/%s", constants.AddonURL, addonID)
return addon.Request.Get(url, queryParams, extraHeaders)
}

// Delete deletes the addon having the given addonID.
func (addon *Addon) Delete(addonID string, queryParams map[string]interface{}, extraHeaders map[string]string) (map[string]interface{}, error) {
url := fmt.Sprintf("%s/%s", constants.ADDON_URL, addonID)
url := fmt.Sprintf("%s/%s", constants.AddonURL, addonID)
return addon.Request.Delete(url, queryParams, extraHeaders)
}
4 changes: 2 additions & 2 deletions resources/addon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
const TestAddonID = "ao_8sg8LU73Y3ieav"

func TestFetchAddon(t *testing.T) {
url := constants.ADDON_URL + "/" + TestAddonID
url := constants.AddonURL + "/" + TestAddonID
teardown, fixture := utils.StartMockServer(url, "fake_addon")
defer teardown()
body, err := utils.Client.Addon.Fetch(TestAddonID, nil, nil)
Expand All @@ -22,7 +22,7 @@ func TestFetchAddon(t *testing.T) {
}

func TestAddonDelete(t *testing.T) {
url := constants.ADDON_URL + "/" + TestAddonID
url := constants.AddonURL + "/" + TestAddonID
teardown, fixture := utils.StartMockServer(url, "fake_addon")
defer teardown()
body, err := utils.Client.Addon.Delete(TestAddonID, nil, nil)
Expand Down
2 changes: 1 addition & 1 deletion resources/card.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ type Card struct {

// Fetch fetches card having the given cardID.
func (card *Card) Fetch(cardID string, queryParams map[string]interface{}, extraHeaders map[string]string) (map[string]interface{}, error) {
url := fmt.Sprintf("%s/%s", constants.CARD_URL, cardID)
url := fmt.Sprintf("%s/%s", constants.CardURL, cardID)
return card.Request.Get(url, queryParams, extraHeaders)
}
2 changes: 1 addition & 1 deletion resources/card_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
const TestCardID = "fake_card_id"

func TestCardFetch(t *testing.T) {
url := constants.CARD_URL + "/" + TestCardID
url := constants.CardURL + "/" + TestCardID
teardown, fixture := utils.StartMockServer(url, "fake_card")
defer teardown()
body, err := utils.Client.Card.Fetch(TestCardID, nil, nil)
Expand Down
6 changes: 3 additions & 3 deletions resources/customer.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ type Customer struct {

// Fetch fetches customer having the given cutomerID.
func (cust *Customer) Fetch(customerID string, queryParams map[string]interface{}, extraHeaders map[string]string) (map[string]interface{}, error) {
url := fmt.Sprintf("%s/%s", constants.CUSTOMER_URL, customerID)
url := fmt.Sprintf("%s/%s", constants.CustomerURL, customerID)
return cust.Request.Get(url, queryParams, extraHeaders)
}

// Create creates a new customer for the given data.
func (cust *Customer) Create(data map[string]interface{}, extraHeaders map[string]string) (map[string]interface{}, error) {
return cust.Request.Post(constants.CUSTOMER_URL, data, extraHeaders)
return cust.Request.Post(constants.CustomerURL, data, extraHeaders)
}

// Edit updates the customer having the given customerID.
func (cust *Customer) Edit(customerID string, data map[string]interface{}, extraHeaders map[string]string) (map[string]interface{}, error) {

url := fmt.Sprintf("%s/%s", constants.CUSTOMER_URL, customerID)
url := fmt.Sprintf("%s/%s", constants.CustomerURL, customerID)

return cust.Request.Post(url, data, extraHeaders)
}
6 changes: 3 additions & 3 deletions resources/customer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
const TestCustomerID = "fake_customer_id"

func TestCustomerFetch(t *testing.T) {
url := constants.CUSTOMER_URL + "/" + TestCustomerID
url := constants.CustomerURL + "/" + TestCustomerID
teardown, fixture := utils.StartMockServer(url, "fake_customer")
defer teardown()
body, err := utils.Client.Customer.Fetch(TestCustomerID, nil, nil)
Expand All @@ -22,7 +22,7 @@ func TestCustomerFetch(t *testing.T) {
}

func TestCustomerCreate(t *testing.T) {
teardown, fixture := utils.StartMockServer(constants.CUSTOMER_URL, "fake_customer")
teardown, fixture := utils.StartMockServer(constants.CustomerURL, "fake_customer")
defer teardown()
params := map[string]interface{}{
"name": "test",
Expand All @@ -35,7 +35,7 @@ func TestCustomerCreate(t *testing.T) {
}

func TestCustomerEdit(t *testing.T) {
url := constants.CUSTOMER_URL + "/" + TestCustomerID
url := constants.CustomerURL + "/" + TestCustomerID
teardown, fixture := utils.StartMockServer(url, "fake_customer")
defer teardown()
params := map[string]interface{}{
Expand Down
6 changes: 3 additions & 3 deletions resources/invoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ type Invoice struct {

// All fetches multiple invoices for the given queryParams.
func (inv *Invoice) All(queryParams map[string]interface{}, extraHeaders map[string]string) (map[string]interface{}, error) {
return inv.Request.Get(constants.INVOICE_URL, queryParams, extraHeaders)
return inv.Request.Get(constants.InvoiceURL, queryParams, extraHeaders)
}

// Fetch fetches an invoice having the given invoiceID.
func (inv *Invoice) Fetch(invoiceID string, queryParams map[string]interface{}, extraHeaders map[string]string) (map[string]interface{}, error) {

url := fmt.Sprintf("%s/%s", constants.INVOICE_URL, invoiceID)
url := fmt.Sprintf("%s/%s", constants.InvoiceURL, invoiceID)

return inv.Request.Get(url, queryParams, extraHeaders)
}

// Create creates a new invoice for the given data.
func (inv *Invoice) Create(data map[string]interface{}, extraHeaders map[string]string) (map[string]interface{}, error) {
return inv.Request.Post(constants.INVOICE_URL, data, extraHeaders)
return inv.Request.Post(constants.InvoiceURL, data, extraHeaders)
}
8 changes: 4 additions & 4 deletions resources/invoice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
const TestInvoiceID = "fake_invoice_id"

func TestInvoiceAll(t *testing.T) {
url := constants.INVOICE_URL
url := constants.InvoiceURL
teardown, fixture := utils.StartMockServer(url, "invoice_collection")
defer teardown()
body, err := utils.Client.Invoice.All(nil, nil)
Expand All @@ -22,7 +22,7 @@ func TestInvoiceAll(t *testing.T) {
}

func TestInvoiceAllWithOptions(t *testing.T) {
url := constants.INVOICE_URL
url := constants.InvoiceURL
teardown, fixture := utils.StartMockServer(url, "invoice_collection_with_one_invoice")
defer teardown()
data := map[string]interface{}{
Expand All @@ -35,7 +35,7 @@ func TestInvoiceAllWithOptions(t *testing.T) {
}

func TestInvoiceFetch(t *testing.T) {
url := constants.INVOICE_URL + "/" + TestInvoiceID
url := constants.InvoiceURL + "/" + TestInvoiceID
teardown, fixture := utils.StartMockServer(url, "fake_invoice")
defer teardown()
body, err := utils.Client.Invoice.Fetch(TestInvoiceID, nil, nil)
Expand All @@ -45,7 +45,7 @@ func TestInvoiceFetch(t *testing.T) {
}

func TestInvoiceCreate(t *testing.T) {
url := constants.INVOICE_URL
url := constants.InvoiceURL
teardown, fixture := utils.StartMockServer(url, "fake_invoice")
defer teardown()
line_item := map[string]interface{}{
Expand Down
10 changes: 5 additions & 5 deletions resources/order.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,31 @@ type Order struct {

// All fetches multiple orders for the given query params.
func (order *Order) All(queryParams map[string]interface{}, extraHeaders map[string]string) (map[string]interface{}, error) {
return order.Request.Get(constants.ORDER_URL, queryParams, extraHeaders)
return order.Request.Get(constants.OrderURL, queryParams, extraHeaders)
}

// Fetch fetches an order having the given orderID.
func (order *Order) Fetch(orderID string, queryParams map[string]interface{}, extraHeaders map[string]string) (map[string]interface{}, error) {

url := fmt.Sprintf("%s/%s", constants.ORDER_URL, orderID)
url := fmt.Sprintf("%s/%s", constants.OrderURL, orderID)
return order.Request.Get(url, queryParams, extraHeaders)
}

// Create creates a new order for the given data
func (order *Order) Create(data map[string]interface{}, extraHeaders map[string]string) (map[string]interface{}, error) {
return order.Request.Post(constants.ORDER_URL, data, extraHeaders)
return order.Request.Post(constants.OrderURL, data, extraHeaders)
}

// Edit updates an order having the given orderID.
func (order *Order) Edit(orderID string, data map[string]interface{}, extraHeaders map[string]string) (map[string]interface{}, error) {

url := fmt.Sprintf("%s/%s", constants.ORDER_URL, orderID)
url := fmt.Sprintf("%s/%s", constants.OrderURL, orderID)
return order.Request.Put(url, data, extraHeaders)
}

// Payments fetches the payments for the given orderID.
func (order *Order) Payments(orderID string, queryParams map[string]interface{}, extraHeaders map[string]string) (map[string]interface{}, error) {

url := fmt.Sprintf("%s/%s/payments", constants.ORDER_URL, orderID)
url := fmt.Sprintf("%s/%s/payments", constants.OrderURL, orderID)
return order.Request.Get(url, queryParams, extraHeaders)
}