Giter Club home page Giter Club logo

go-pano's Introduction

Gin-Framework

Dev Configuration

Run Docker Service

docker-compose up

SQL init

If you are the first time starting this project, just use below sql commands to login.

INSERT INTO `Users` (`user_id`, `name`, `account`, `password`, `roles_string`, `status`) VALUES
(1, 'ADMIN', '__pano_admin__', '$2a$10$94v4wlp6ZRanI6Xv1k4hyePZJlTJf.o08fSUqPby/mABlGGgRiRAa', '[\"admin\"]', 1);
INSERT INTO `Clinic` (`clinic_id`, `name`, `start_at`, `end_at`, `quota_per_month`, `token`) VALUES
(1, '測試診所', '2022-10-10', '2099-12-31', 200, 'rHsxKe6qPxxoZJh2oPJPk2mVzNFB5XmfOnkLpCwvbhnOnbU9i3');

Prod Configuration

1. Copy config.yml to config-prod.yml & change the dsn, mode of mysql

server:
  version: v0.1
  addr: :80
  mode: prod
  static_dir: ./static
  public_dir: ./public
  # view_dir: ./view
  # upload_dir: ./storage
  max_multipart_memory: 50

python:
  dev_host: 127.0.0.1
  test_host: 127.0.0.1
  prod_host: pano-python

database-in-docker:
  dialect: mysql
  datasource: <user>:<password>@tcp(mysql:3306)/pano?charset=utf8mb4&timeout=10s&parseTime=True
  dir: migrations
  table: migrations
  max_idle_conns: 2
  max_open_conns: 16

database:
  dialect: mysql
  datasource: <user>:<password>@tcp(mysql:3306)/pano?charset=utf8mb4&timeout=10s&parseTime=True
  dir: migrations
  table: migrations
  max_idle_conns: 2
  max_open_conns: 16

2. Copy docker-compose.yml to Copy docker-compose-prod.yml, change the config of mysql, and chang the target of pano-go service.

version: "3"
services:
  pano-python:
    image: poabob/pano-python:prod-1.0.0
    build: ./dist/python
    container_name: pano-python
    volumes:
      - ./dist/static:/app/go/static
    ports:
      - 5001:5001
  pano-go:
    image: poabob/pano-go:prod-1.0.0
    build: 
      context: .
      dockerfile: Dockerfile
      target: prod
    container_name: pano-go
    volumes:
      - ./dist/log:/app/go/log
      - ./dist/static:/app/go/static
      - ./dist/public:/app/go/public
    depends_on:
      - mysql
    ports:
      - 80:80
  mysql:
    image: mariadb:10.9
    container_name: mysql
    restart: always
    environment:
      MYSQL_DATABASE: "<DB>"
      MYSQL_USER: "<user>"
      MYSQL_PASSWORD: "<password>"
      MYSQL_RANDOM_ROOT_PASSWORD: true
    ports:
      - "3306:3306"
    volumes:
      - ./dist/mysql:/var/lib/mysql

3. Start the service

docker-compose -f docker-compose-prod.yml up

Generate swag document

All comments were written in router/router.go, so you need to find the path.

# In Docker
docker exec pano-go swag init -g ./router/router_v1.go -o ./docs

# In real mechine
swag init -g ./router/router_v1.go -o ./docs

Generate wire service

  1. Edit router/wire.go and write the initialization of dependency injections.
  • Example
//go:build wireinject
// +build wireinject

package router_v1

import (
	"github.com/google/wire"

	clinic_repository "go-pano/domain/repository/clinic"

	clinic_service "go-pano/domain/service/clinic"
	"go-pano/utils"
)

func initClinicService() clinic_service.IClinicService {
	wire.Build(
		clinic_service.NewClinicService,
		clinic_repository.NewClinicRepository,
		utils.NewDBInstance,
	)
	return nil
}
  1. When you added the relationship of each class, run command wire <relative_path>..
# In Docker
docker exec pano-go wire ./router/.

# In real mechine
wire ./router/.
  1. Add the functions of dependency injections where you want.
package router_v1

import (
	"github.com/gin-gonic/gin"
	"go-pano/domain/delivery/http"
)

func NewRouter(app *gin.Engine) {

	api := app.Group("/api")
	{
		// After
		http.NewClinicHandler(api, initClinicService())

        // Before
        // cr := clinic_repository.NewClinicRepository(db)
		// cs := clinic_service.NewClinicService(cr)
		// http.NewClinicHandler(api, cs)

	}

}

Use Protocol Buffers

Generate all pb files.

# In Docker
docker exec pano-go protoc ./protos/*/*.proto  --go_out=plugins=grpc:. --go_opt=paths=source_relative

# In real mechine
protoc ./protos/*/*.proto  --go_out=plugins=grpc:. --go_opt=paths=source_relative

Furture Table

CREATE TABLE IF NOT EXISTS `Record` (
  `record_id` int PRIMARY KEY AUTO_INCREMENT COMMENT '紀錄ID',
  `clinic_id` int DEFAULT 0 COMMENT '診所ID',
  `predict_id` int DEFAULT 0 COMMENT '預測ID',
  `score` int NOT NULL DEFAULT 80 COMMENT '準確度',
  `comment` varchar(1024) NOT NULL DEFAULT "" COMMENT '準確度評論'
)ENGINE = InnoDB DEFAULT CHARSET=utf8mb4;

TODO

  • Write down the real process
  • Finish Predict Unit Tests
  • User RBAC control
  • Clinic Token Request
  • Record API
    • services used per month every clinic
    • services score list

go-pano's People

Contributors

poabob avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.