Skip to content

Instantly share code, notes, and snippets.

@KimTrijnh
Created June 20, 2019 07:49
Show Gist options
  • Save KimTrijnh/88bc1bc803e65e42fd52ef4c6aa61400 to your computer and use it in GitHub Desktop.
Save KimTrijnh/88bc1bc803e65e42fd52ef4c6aa61400 to your computer and use it in GitHub Desktop.
hospify-core/

Hospify API service

Hospify Core is a backend service. It provides REST API for Hospify

Prerequired

  • Install postgresql (prefer v10)
  • Install golang, set up path (Unix only, google for Windows)
# .bash_profile
export GOPATH="/your/go/path" # /Users/<username>/Documents/go
export PATH=$PATH:$GOROOT/bin
export PATH=$PATH:$GOPATH/bin
  • Install redis

Deployment

# make root dir and cd to new dir
$ mkdir hospify-dev && cd hospify-dev # or any name you want

# clone projects
$ git clone git@github.com:leovinh/hospify-master.git
$ git clone git@github.com:leovinh/hospify-core.git

# pwd: hospify-master
$ cp db/dbconf.yml.example db/dbconf.yml # edit datatabase config for migration in dbconf.yml
$ goose up 
# pwd: hospify-core
# cuz we will run in host network mode so we must edit config.go
$ cp config/config.go.example config/config.go

# pwd: hospify-dev
$ docker build --rm -t hospify-image-dev -f hospify-core/Dockerfile .

# Create volume to backup resource
$ docker volume create --name HospifyDevResource
# test run
docker run --net=host --env-file hospify-core/.env.beta -it --rm --name hospify-dev hospify-image-dev
# run in detach mode
# Maping resources dir
$ docker run -v HospifyDevResource:/go/src/hospify-core/resources -d --net=host -it --rm --name hospify-dev hospify-image-dev

Installation dev

  • Clone project in go source $GOPATH/src
git clone git@github.com:leovinh/hospify-master.git
git clone git@github.com:leovinh/hospify-core.git
  • Copy the configurations in hospify-core project
cp config/config.go.example config/config.go

Migration data

cd hospify-master
go get bitbucet.org/liamstask/goose/cmd/goose
cp db/dbconf.yml.example db/dbconf.yml
goose up
  • Install and run app hospify-core
go get
go run main.go
  • Build executable binary file
go build
./hospify-core

Deploy production

 go build

 # Run as a daemonize process
 ./startup <start,stop,restart>

Documents

Notes

In window, to run .env when development, in hospify-core/main.go

...

// init is invoked before main()
func init() {
	// loads values from .env into the system
	if err := godotenv.Load(); err != nil {
		log.Print("No .env file found")
	}
}

func main() {

	conf := config.New()

	if config.GetAppMode() == gin.ReleaseMode {
		logrus.SetLevel(logrus.WarnLevel)
	} else {
		logrus.SetLevel(logrus.DebugLevel)
	}

	logrus.AddHook(filename.NewHook())
	logrus.SetFormatter(&logrus.TextFormatter{
		FullTimestamp:          true,
		ForceColors:            true,
		DisableLevelTruncation: true,
	})

	logrus.Info("API say Halo :D")

	// PSQL
	cf := resource.ResourceConfig{
		PostgreSQLLogger: config.GetAppMode() != gin.ReleaseMode,
		IsEnablePostgres: true,

		// to use variable from .env
		PostgreSQLDatabase: "postgres://" + conf.Psql.DbUser + ":" + conf.Psql.DbPwd + "@" + conf.Psql.DbHost + ":" + conf.Psql.DbPort + "/" + conf.Psql.DbName + "?sslmode=disable",

		IsEnableRedis: config.IsEnableRedis(),
		RedisPrefix:   config.GetRedisKeyPrefix(),
		RedisDBURI:    config.GetRedisDBURI(),
	}

Create booking flow

  1. Find/create guest
  2. Get booking count
  3. Checking room info
  • Nomal: checking room id (if room client send Room.ID)
  • CMS: find mapped room type, auto assign room for, booking if posible, find company
  1. Create booking
  2. Update hotel booking count
  3. Create occupancy forecast
  4. Create folio
  5. Create charges

Copyright (c) Hospify Ltd. All rights reserved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment