-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Communication] - #2kb2z3e - [Library][Span and Trace] Wappin Adjustm…
…ent (#2) * - Initialize commit 🎉 - Add errors ✨ - Add Makefile ✨ - Use go 1.17 📌 - Add TODOS 🚧 - Work on some leftovers for token manager 🚧 * - Add .env for integration test ✨ - Change .gitignore 🙈 - Update dependencies 📦 - Add integration_test.go ✅ - Add token manager and storage for wappin ✨ - Set default client id and project id for request whatsapp message ✨ - Refactor funtion to reduce redundancies ♻️ * - Remove custom IPs since wappin only allow predefined IPs 🔥 - Update tests ✅
- Loading branch information
1 parent
918cdc5
commit 19c8c41
Showing
15 changed files
with
1,271 additions
and
278 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
WAPPIN_CLIENT_ID={{wappin client id}} | ||
WAPPIN_PROJECT_ID={{wappin project id}} | ||
WAPPIN_SECRET_KEY={{wappin secret key}} | ||
WAPPIN_CLIENT_KEY={{wappin client key}} | ||
PHONE_NUMBER={{your phone number}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,10 @@ | ||
.env | ||
/vendor | ||
wappin | ||
wappin | ||
|
||
# Editor Configs | ||
.vscode | ||
.idea | ||
|
||
# Environment Files | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
.ONESHELL: | ||
SHELL=/bin/sh | ||
|
||
# Input Variables with Default Value | ||
GO_VERSION?=1.17 | ||
GOOS?=linux | ||
GOARM?=7 | ||
GOARCH?=amd64 | ||
CGO_ENABLED?=0 | ||
DOC_PORT?=6060 | ||
|
||
.PHONY: default | ||
default: help | ||
@# Help: The default target of the Makefile. | ||
|
||
.PHONY: help | ||
help: | ||
@# Help: Show the help description. | ||
|
||
printf "%-20s %s\n" "Target" "Description" | ||
printf "%-20s %s\n" "------" "-----------" | ||
make -pqR : 2>/dev/null \ | ||
| awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' \ | ||
| sort \ | ||
| egrep -v -e '^[^[:alnum:]]' -e '^$@$$' \ | ||
| xargs -I _ sh -c 'printf "%-20s " _; make _ -nB | (grep -i "^# Help:" || echo "") | tail -1 | sed "s/^# Help: //g"' | ||
|
||
.PHONY: mod-tidy | ||
mod-tidy: | ||
@# Help: Tidy the Go dependencies. | ||
|
||
@echo go mod tidy -compat=${GO_VERSION} -v | ||
go mod tidy -compat=${GO_VERSION} -v | ||
|
||
.PHONY: lint | ||
lint: | ||
@# Help: Lint the Go code. | ||
|
||
go fmt . | ||
go fmt $(go list ./... | grep -v /vendor/) | ||
|
||
.PHONY: generate | ||
generate: | ||
@# Help: Run the Go generator. | ||
|
||
go install -v github.com/vektra/mockery/v2@latest | ||
go generate -v ./... | ||
|
||
.PHONY: test | ||
test: generate | ||
@# Help: Run the go test. | ||
|
||
go test -v -race ./... | ||
|
||
.PHONY: test-coverage | ||
test-coverage: generate | ||
@# Help: Run the test to get coverage. | ||
|
||
go test -race -covermode=atomic -coverprofile=profile.cov $(go list ./... | grep -v /vendor/) | ||
|
||
.PHONY: coverage | ||
coverage: test-coverage | ||
@# Help: Run all actions to extract coverage data from the cover profile. | ||
go tool cover -func profile.cov | ||
|
||
# last line will be number of total coverage | ||
go tool cover -func profile.cov | tail -n1 | awk '{print $$3}' | ||
|
||
.PHONY: mod-download | ||
mod-download: | ||
@# Help: Download all the depencies needed for the Golang service. | ||
|
||
GOOS=${GOOS} GOARM=${GOARM} GOARCH=${GOARCH} go mod download | ||
|
||
.PHONY: doc | ||
doc: | ||
@# Help: Show the package documentation in the local server. | ||
|
||
godoc -http=:${DOC_PORT} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,19 @@ | ||
# Wappin | ||
Wappin API client library. https://wappin.id | ||
|
||
[](https://pkg.go.dev/github.com/flip-id/wappin) | ||
[](https://goreportcard.com/report/github.com/flip-id/wappin) | ||
|
||
Wappin API client library. https://wappin.id. | ||
|
||
# How to Test | ||
|
||
To run the integration tests, we need to do the following: | ||
1. Make a new copy of `.env.example` to `.env` by running this command below: | ||
```bash | ||
cat .env.example > .env | ||
``` | ||
2. Fill the new .env with the parameter that we already prepared. | ||
3. Run the tests by running this command: | ||
```bash | ||
go test -v -race -tags=integration -covermode=atomic ./... | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package wappin | ||
|
||
import ( | ||
"fmt" | ||
"github.com/fairyhunter13/reflecthelper/v5" | ||
"github.com/pkg/errors" | ||
"net/http" | ||
) | ||
|
||
// List of errors used in this package. | ||
var ( | ||
ErrNilArguments = errors.New("nil arguments") | ||
) | ||
|
||
// Error represents the error for Wappin. | ||
type Error struct { | ||
Status string `json:"status"` | ||
Message string `json:"message"` | ||
} | ||
|
||
// Error implements the error interface. | ||
func (e *Error) Error() string { | ||
return fmt.Sprintf("error Wappin status:%s message:%s", e.Status, e.Message) | ||
} | ||
|
||
// CastError casts the response to Wappin error. | ||
func CastError(status string, message string) *Error { | ||
return &Error{ | ||
Status: status, | ||
Message: message, | ||
} | ||
} | ||
|
||
func getError(statusCode int, status string, message string) (err error) { | ||
if !(reflecthelper.GetInt(status) >= http.StatusBadRequest || | ||
statusCode >= http.StatusBadRequest) { | ||
return | ||
} | ||
|
||
err = CastError(status, message) | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,48 @@ | ||
module github.com/flip-id/wappin | ||
|
||
go 1.14 | ||
go 1.17 | ||
|
||
require ( | ||
github.com/go-resty/resty/v2 v2.6.0 | ||
github.com/jarcoal/httpmock v1.0.8 | ||
github.com/joho/godotenv v1.4.0 | ||
github.com/kr/pretty v0.1.0 // indirect | ||
github.com/sirupsen/logrus v1.8.1 | ||
github.com/stretchr/testify v1.7.0 | ||
github.com/fairyhunter13/dotenv v1.1.3 | ||
github.com/fairyhunter13/phone v0.0.3 | ||
github.com/fairyhunter13/pool v0.0.0-20211114080908-60a828fe746c | ||
github.com/fairyhunter13/reflecthelper/v5 v5.1.1 | ||
github.com/flip-id/valuefirst v1.0.4 | ||
github.com/gofiber/fiber/v2 v2.35.0 | ||
github.com/gojek/heimdall/v7 v7.0.2 | ||
github.com/pkg/errors v0.9.1 | ||
github.com/stretchr/testify v1.7.1 | ||
) | ||
|
||
require ( | ||
github.com/DataDog/datadog-go v3.7.1+incompatible // indirect | ||
github.com/Popog/deepcopy v0.0.0-20160519164043-14c73c14458b // indirect | ||
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5 // indirect | ||
github.com/andybalholm/brotli v1.0.4 // indirect | ||
github.com/cactus/go-statsd-client/statsd v0.0.0-20200423205355-cb0885a1018c // indirect | ||
github.com/cespare/xxhash/v2 v2.1.2 // indirect | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect | ||
github.com/fairyhunter13/envcompact v0.2.0 // indirect | ||
github.com/fairyhunter13/go-lexer v1.0.0-1 // indirect | ||
github.com/fairyhunter13/task/v2 v2.0.0 // indirect | ||
github.com/go-redis/redis/v8 v8.11.5 // indirect | ||
github.com/gojek/valkyrie v0.0.0-20180215180059-6aee720afcdf // indirect | ||
github.com/golang/protobuf v1.5.2 // indirect | ||
github.com/klauspost/compress v1.15.0 // indirect | ||
github.com/mitchellh/mapstructure v1.4.1 // indirect | ||
github.com/nyaruka/phonenumbers v1.1.0 // indirect | ||
github.com/panjf2000/ants v1.3.0 // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect | ||
github.com/reiver/go-cast v0.0.0-20210208184015-0ace357373b2 // indirect | ||
github.com/stretchr/objx v0.3.0 // indirect | ||
github.com/valyala/bytebufferpool v1.0.0 // indirect | ||
github.com/valyala/fasthttp v1.38.0 // indirect | ||
github.com/valyala/tcplisten v1.0.0 // indirect | ||
golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9 // indirect | ||
golang.org/x/text v0.3.7 // indirect | ||
google.golang.org/protobuf v1.26.0 // indirect | ||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect | ||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect | ||
) |
Oops, something went wrong.