Skip to content

Commit

Permalink
Merge pull request #5 from ardityawahyu/fixing-linter
Browse files Browse the repository at this point in the history
adding badges, fix linter and add
  • Loading branch information
ardityawahyu authored Dec 11, 2019
2 parents 4e4cf5f + 2a7f5ed commit b58698e
Show file tree
Hide file tree
Showing 11 changed files with 120 additions and 33 deletions.
26 changes: 26 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Golang CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-go/ for more details
version: 2
jobs:
build:
docker:
# specify the version
- image: circleci/golang:1.13

# Specify service dependencies here if necessary
# CircleCI maintains a library of pre-built images
# documented at https://circleci.com/docs/2.0/circleci-images/
# - image: circleci/postgres:9.4

#### TEMPLATE_NOTE: go expects specific checkout path representing url
#### expecting it in the form of
#### /go/src/github.com/circleci/go-tool
#### /go/src/bitbucket.org/circleci/go-tool
working_directory: /go/src/github.com/kitabisa/buroq
steps:
- checkout

# specify any bash command here prefixed with `run: `
- run: go get -v -t -d ./...
- run: go test -v ./...
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Kitabisa

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
[![Go Report Card](https://goreportcard.com/badge/github.com/kitabisa/buroq)](https://goreportcard.com/report/github.com/kitabisa/buroq)
![technology:go](https://img.shields.io/badge/technology-go-blue.svg)
[![Maintainability](https://api.codeclimate.com/v1/badges/b6e84c6b2bb2a819b198/maintainability)](https://codeclimate.com/github/kitabisa/buroq/maintainability)

# buroq

this is a bootstrap service build with GO for our cookie cutter.
Expand Down
57 changes: 37 additions & 20 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@ import (
"fmt"
"os"

"github.com/gomodule/redigo/redis"
"github.com/kitabisa/buroq/config"
"github.com/kitabisa/buroq/internal/app/appcontext"
"github.com/kitabisa/buroq/internal/app/commons"
"github.com/kitabisa/buroq/internal/app/repository"
"github.com/kitabisa/buroq/internal/app/server"
"github.com/kitabisa/buroq/internal/app/service"
"github.com/kitabisa/perkakas/v2/log"
"github.com/kitabisa/perkakas/v2/metrics/influx"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"gopkg.in/gorp.v2"
)

// rootCmd represents the base command when called without any subcommands
Expand Down Expand Up @@ -44,30 +47,44 @@ func start() {
logger := log.NewLogger("buroq")

app := appcontext.NewAppContext(cfg)
dbMysql, err := app.GetDBInstance(appcontext.DBDialectMysql)
if err != nil {
logrus.Fatalf("Failed to start, error connect to DB MySQL | %v", err)
return
var err error

var dbMysql *gorp.DbMap
if cfg.GetBool("mysql.is_enabled") {
dbMysql, err = app.GetDBInstance(appcontext.DBDialectMysql)
if err != nil {
logrus.Fatalf("Failed to start, error connect to DB MySQL | %v", err)
return
}
}

dbPostgre, err := app.GetDBInstance(appcontext.DBDialectPostgres)
if err != nil {
logrus.Fatalf("Failed to start, error connect to DB Postgre | %v", err)
return
var dbPostgre *gorp.DbMap
if cfg.GetBool("postgre.is_enabled") {
dbPostgre, err = app.GetDBInstance(appcontext.DBDialectPostgres)
if err != nil {
logrus.Fatalf("Failed to start, error connect to DB Postgre | %v", err)
return
}
}

cache := app.GetCachePool()
cacheConn, err := cache.Dial()
if err != nil {
logrus.Fatalf("Failed to start, error connect to DB Cache | %v", err)
return
var cache *redis.Pool
if cfg.GetBool("cache.is_enabled") {
cache = app.GetCachePool()
cacheConn, err := cache.Dial()
if err != nil {
logrus.Fatalf("Failed to start, error connect to DB Cache | %v", err)
return
}
defer cacheConn.Close()
}
defer cacheConn.Close()

influx, err := app.GetInfluxDBClient()
if err != nil {
logrus.Fatalf("Failed to start, error connect to DB Influx | %v", err)
return
var influx *influx.Client
if cfg.GetBool("influx.is_enabled") {
influx, err = app.GetInfluxDBClient()
if err != nil {
logrus.Fatalf("Failed to start, error connect to DB Influx | %v", err)
return
}
}

opt := commons.Options{
Expand Down Expand Up @@ -105,11 +122,11 @@ func wiringRepository(repoOption repository.Option) *repository.Repository {
return &repo
}

func wiringService(serviceOption service.Option) *service.Service {
func wiringService(serviceOption service.Option) *service.Services {
// wiring up all services
hc := service.NewHealthCheck(serviceOption)

svc := service.Service{
svc := service.Services{
HealthCheck: hc,
}

Expand Down
1 change: 1 addition & 0 deletions internal/app/commons/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"gopkg.in/gorp.v2"
)

// Options common option for all object that needed
type Options struct {
Config config.Provider
DbMysql *gorp.DbMap
Expand Down
2 changes: 2 additions & 0 deletions internal/app/driver/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"gopkg.in/gorp.v2"
)

// DBMysqlOption options for mysql connection
type DBMysqlOption struct {
Host string
Port int
Expand All @@ -21,6 +22,7 @@ type DBMysqlOption struct {
ConnMaxLifetime time.Duration
}

// NewMysqlDatabase return gorp dbmap object with MySQL options param
func NewMysqlDatabase(option DBMysqlOption) (*gorp.DbMap, error) {
db, err := sql.Open("mysql", fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?%s", option.Username, option.Password, option.Host, option.Port, option.DBName, option.AdditionalParameters))
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions internal/app/driver/postgre.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"gopkg.in/gorp.v2"
)

// DBPostgreOption options for postgre connection
type DBPostgreOption struct {
Host string
Port int
Expand All @@ -17,6 +18,7 @@ type DBPostgreOption struct {
MaxPoolSize int
}

// NewPostgreDatabase return gorp dbmap object with postgre options param
func NewPostgreDatabase(option DBPostgreOption) (*gorp.DbMap, error) {
db, err := sql.Open("postgres", fmt.Sprintf("host=%s port=%d user=%s dbname=%s password=%s sslmode=disable", option.Host, option.Port, option.Username, option.DBName, option.Password))
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions internal/app/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/kitabisa/buroq/internal/app/service"
)

// HandlerOption option for handler, including all service
type HandlerOption struct {
commons.Options
*service.Services
Expand Down
33 changes: 21 additions & 12 deletions internal/app/handler/health_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,40 @@ import (
"net/http"
)

// HealthCheckHandler object for health check handler
type HealthCheckHandler struct {
HandlerOption
http.Handler
}

// HealthCheck checking if all work well
func (h HealthCheckHandler) HealthCheck(w http.ResponseWriter, r *http.Request) (data interface{}, pageToken *string, err error) {
err = h.Services.HealthCheck.HealthCheckDbMysql()
if err != nil {
return
if h.HandlerOption.Config.GetBool("mysql.is_enabled") {
err = h.Services.HealthCheck.HealthCheckDbMysql()
if err != nil {
return
}
}

err = h.Services.HealthCheck.HealthCheckDbPostgres()
if err != nil {
return
if h.HandlerOption.Config.GetBool("postgre.is_enabled") {
err = h.Services.HealthCheck.HealthCheckDbPostgres()
if err != nil {
return
}
}

err = h.Services.HealthCheck.HealthCheckDbCache()
if err != nil {
return
if h.HandlerOption.Config.GetBool("cache.is_enabled") {
err = h.Services.HealthCheck.HealthCheckDbCache()
if err != nil {
return
}
}

err = h.Services.HealthCheck.HealthCheckInflux()
if err != nil {
return
if h.HandlerOption.Config.GetBool("influx.is_enabled") {
err = h.Services.HealthCheck.HealthCheckInflux()
if err != nil {
return
}
}

return
Expand Down
2 changes: 1 addition & 1 deletion internal/app/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type Option struct {
*repository.Repository
}

// Service all service object injected here
// Services all service object injected here
type Services struct {
HealthCheck IHealthCheck
}
4 changes: 4 additions & 0 deletions params/buroq.toml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ name = "buroq"
secret = "any_secret"

[postgre]
is_enabled = false
host = "your_db_host"
port = 5432
name = "buroq"
Expand All @@ -13,6 +14,7 @@ password = "your_password"
pool_size = 5

[mysql]
is_enabled = false
host = "your_db_host"
port = 3306
name = "buroq"
Expand All @@ -24,6 +26,7 @@ conn_lifetime_max = "0s" #maximum duration connection lifetime max
additional_parameters = "charset=utf8&parseTime=True&loc=Asia%2fJakarta&time_zone=%27%2B07%3A00%27"

[cache]
is_enabled = false
host = "your_cache_host"
port = 6379
dial_connect_timeout = "5s"
Expand All @@ -41,6 +44,7 @@ locker_retry_delay = "1s"
locker_expiry = "5s"

[influx]
is_enabled = false
host = "your_influx_host"
user = "your_username"
pass = "your_password"
Expand Down

0 comments on commit b58698e

Please sign in to comment.