Giter Club home page Giter Club logo

myply's Introduction

myply Server

This is a repository for myply server

Screen Shot 2022-07-31 at 7 59 11 PM

local

  • pre-commit
$ cp pre-commit.example .git/hooks/pre-commit
$ chmod +x .git/hooks/pre-commit
  • setup
make setup
  • run
$ make local
GO111MODULE=on go run ./application/cmd/main.go

 ┌───────────────────────────────────────────────────┐ 
 │                   Fiber v2.34.1                   │ 
 │               http://127.0.0.1:3000               │ 
 │       (bound on host 0.0.0.0 and port 3000)       │ 
 │                                                   │ 
 │ Handlers ............. 2  Processes ........... 1 │ 
 │ Prefork ....... Disabled  PID ............. 11610 │ 
 └───────────────────────────────────────────────────┘ 

# 127.0.0.1:8080/swagger/index.html
  • docker
$ make docker.fiber

prod

directory structure

├── application // Interface layer and Application Services in hexagonal architecture
   ├── cmd // command line interface
   ├── controller // http controller
   ├── middleware // http middleware, it can wrap errors or set request uuid or jwt authorization
   └── routes // http router
├── domain // domain layer
   ├── entity
   ├── repository // same as Port in hexagonal architecture
   ├── service // domain service layer
   └── vo // value object
├── go.mod
├── infrastructure // infrastructure layer in hexagonal
   ├── clients // external APIs (E.g. google client, firebase client ..)
   ├── configs // configuration of fiber app 
   ├── logger
   └── persistence // Impl of /domain/repository interface, database persistence layer(E.g. mysql, postgreSQL, mongo, redis ..)
└── pre-commit.example // go fmt before commit

uml

schema

refs

myply's People

Contributors

jiwonkim-park avatar minkj1992 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

myply's Issues

Fix gopls bug with build:wireinject

There is an gopls error in server.go
related this issue

No packages found for open file /some/path/wire.go: .
If this file contains build tags, try adding "-tags=" to your gopls "buildFlag" configuration (see (https://github.com/golang/tools/blob/master/gopls/doc/settings.md#buildflags-string).
Otherwise, see the troubleshooting guidelines for help investigating (https://github.com/golang/tools/blob/master/gopls/doc/troubleshooting.md)

  • server.go
//go:build wireinject
// +build wireinject

package application // bug occured here

so I added buildTags to gopls.

Refactor queries to query

Previously I planned to parse keywords from query string by NLP process.
But youtube already parse keywords so I deprecate that process

Introduce `mongo db`

google cloud sql is not suitable for side-project because a pricing issue.

No matter how I reduced cloud sql spec, the minimum cloud sql price is $8.56/ per month.

Therefore, I consider firestore(nosql) which provides free specs up to a certain request.

  • TODO
    • Checks golang firestore client
    • Checks firestore db schema migration system.
    • Applies DI with wire on myply' /infrastructure/client/firestore.
    • Updates CICD pipeline and deprecate cloud sql on gcp.

Build CI/CD pipeline

Action items

  • github action
  • gcp connect
  • test before push

GCP

pricing

tl;dr

Just use Taiwan region

GCP network

https://cloud.google.com/vpc/network-pricing

  • Ingress ( users -> instance ) is free

Screen Shot 2022-07-07 at 11 07 13 AM

  • egress ( kr -> taiwan $0.05 )

Screen Shot 2022-07-07 at 11 08 19 AM

Cloud run

https://cloud.google.com/run/pricing

  1. Set cpu less than 1, memory 128MiB
  2. Check CPU is only allocated during request processing
  3. Execution env to set First generation
  4. Set autoscaling min number of instances field to 0. (max: 4~5?)

Screen Shot 2022-07-07 at 10 17 45 AM

  • cloud run pricing by region, FYI, seoul is 2nd grade.
    Screen Shot 2022-07-07 at 10 42 21 AM

Cloud SQL

https://cloud.google.com/sql/pricing

  • Set number of vCPU 1 (4로 설정하면 대략 하루 18,000원)

  • Seoul이 vCPU가격이 다른 region에 비해서 훨씬 높다. -> Select Taiwan

  • Taiwan의 경우 us-central들과 가격 정책이 같다.
    Screen Shot 2022-07-07 at 10 28 07 AM

  • lowa
    Screen Shot 2022-07-07 at 10 29 18 AM

  • seoul
    Screen Shot 2022-07-07 at 10 29 47 AM

  • Data Egress(outboud) pricing

    • Set cloud run region same as cloud sql

Screen Shot 2022-07-07 at 10 32 37 AM

Handle configuration by phase

There are two phases

  1. local
  2. prod

To load env variable I picked godotenv

The env variables used for production phase will be managed in the settings of gcp cloud run.
Screen Shot 2022-07-13 at 6 38 02 PM

Build server skeleton

  • Based on Hexagonal arch, build project directory structure
  • Add dependencies fiber, wire, gorm

Get user's memo list

  • 보관함 리스트 > 내 메모 리스트 가져오기
    GET /v1/memos
// response, order by updatedAt
{
  code: ENUM(int), 
	message?: str,
  data: {
		memos: []MemoResponse 
	}
}
  1. Get member from Device-token
  2. Get memos from member

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.