1
0
mirror of https://github.com/raseels-repos/golang-saas-starter-kit.git synced 2025-08-08 22:36:41 +02:00

removed db tags on models

This commit is contained in:
Lee Brown
2019-05-29 18:52:28 -08:00
parent 16dafe29fd
commit fa598fa328
6 changed files with 67 additions and 61 deletions

View File

@ -30,4 +30,6 @@ Jeremy Stone <slycrel@gmail.com>
Nick Stogner <nstogner@users.noreply.github.com>
William Kennedy <bill@ardanlabs.com>
Wyatt Johnson <wyattjoh@gmail.com>
Zachary Johnson <zachjohnsondev@gmail.com>
Zachary Johnson <zachjohnsondev@gmail.com>
Lee Brown <lee@geeksinthewoods.com>
Lucas Brown <lucas@geeksinthewoods.com>

View File

@ -1,12 +1,12 @@
# SaaS Service
Copyright 2019, Geeks Accelerator
accelerator@geeksinthewoods.com.com
twins@geeksaccelerator.com
## Description
Service is a project that provides a starter-kit for a REST based web service. It provides best practices around Go web services using POD architecture and design. It contains the following features:
This is a project that provides a starter-kit for a REST based web service. It provides best practices around Go web services using POD architecture and design. It contains the following features:
* Minimal application web framework.
* Middleware integration.
@ -19,31 +19,57 @@ Service is a project that provides a starter-kit for a REST based web service. I
* Use of Docker, Docker Compose, and Makefiles.
* Vendoring dependencies with Modules, requires Go 1.11 or higher.
This project has the following example services:
* web api - Used to publically expose handlers
* web app - Display and render html.
* schema - Tool for initializing of db and schema migration.
## Local Installation
This project contains three services and uses 3rd party services such as MongoDB and Zipkin. Docker is required to run this software on your local machine.
This project contains three services and uses 3rd party services:
* redis - key / value storage for sessions and other web data. Used only as emphemeral storage.
* postgres - transaction database for persitance of all data.
* datadog - metrics, logging, and tracing
Docker is required to run this software on your local machine.
An AWS account is required for the project to run because of the following dependancies on AWS:
* secret manager
* s3
Required for deploymenet:
* ECS Fargate
* RDS
* Route
### Getting the project
You can use the traditional `go get` command to download this project into your configured GOPATH.
```
$ go get -u geeks-accelerator/oss/saas-starter-kit/example-project
$ go get -u gitlab.com/geeks-accelerator/oss/saas-starter-kit
```
### Go Modules
This project is using Go Module support for vendoring dependencies. We are using the `tidy` and `vendor` commands to maintain the dependencies and make sure the project can create reproducible builds. This project assumes the source code will be inside your GOPATH within the traditional location.
This project is using Go Module support for vendoring dependencies. We are using the `tidy` command to maintain the dependencies and make sure the project can create reproducible builds. This project assumes the source code will be inside your GOPATH within the traditional location.
```
cd $GOPATH/src/geeks-accelerator/oss/saas-starter-kit/example-project
GO111MODULE=on go mod tidy
GO111MODULE=on go mod vendor
```
It's recommended to set use at least go 1.12 and enable go modules.
```bash
echo "export GO111MODULE=on" >> ~/.bash_profile
```
### Installing Docker
Docker is a critical component to managing and running this project. It kills me to just send you to the Docker installation page but it's all I got for now.
Docker is a critical component to managing and running this project.
https://docs.docker.com/install/
@ -51,7 +77,7 @@ If you are having problems installing docker reach out or jump on [Gopher Slack]
## Running The Project
All the source code, including any dependencies, have been vendored into the project. There is a single `dockerfile`and a `docker-compose` file that knows how to build and run all the services.
There is a `docker-compose` file that knows how to build and run all the services. Each service has it's own a `dockerfile`.
A `makefile` has also been provide to make building, running and testing the software easier.
@ -140,6 +166,13 @@ sqlQueryStr = db.Rebind(sqlQueryStr)
For additional details refer to https://jmoiron.github.io/sqlx/#bindvars
### datadog
Datadog has a custom init script to support setting multiple expvar urls for monitoring. The docker-compose file then can set a single env variable.
```bash
DD_EXPVAR=service_name=web-app env=dev url=http://web-app:4000/debug/vars|service_name=web-api env=dev url=http://web-api:4001/debug/vars
```
## What's Next
@ -174,6 +207,8 @@ secretsmanager:DeleteSecret
### TODO:
* update makefile
additianal info required here in readme
need to copy sample.env_docker_compose to .env_docker_compose and defined your aws configs for docker-compose

View File

@ -1,31 +0,0 @@
# Build the Go Binary.
FROM golang:1.12.1 as build
ENV CGO_ENABLED 0
ARG VCS_REF
ARG PACKAGE_NAME
ARG PACKAGE_PREFIX
RUN mkdir -p /go/src/geeks-accelerator/oss/saas-starter-kit/example-project
COPY . /go/src/geeks-accelerator/oss/saas-starter-kit/example-project
WORKDIR /go/src/geeks-accelerator/oss/saas-starter-kit/example-project/cmd/${PACKAGE_PREFIX}${PACKAGE_NAME}
RUN go build -ldflags "-s -w -X main.build=${VCS_REF}" -a -tags netgo
# Run the Go Binary in Alpine.
FROM alpine:3.7
ARG BUILD_DATE
ARG VCS_REF
ARG PACKAGE_NAME
ARG PACKAGE_PREFIX
COPY --from=build /go/src/geeks-accelerator/oss/saas-starter-kit/example-project/cmd/${PACKAGE_PREFIX}${PACKAGE_NAME}/${PACKAGE_NAME} /app/main
COPY --from=build /go/src/geeks-accelerator/oss/saas-starter-kit/example-project/private.pem /app/private.pem
WORKDIR /app
CMD /app/main
LABEL org.opencontainers.image.created="${BUILD_DATE}" \
org.opencontainers.image.title="${PACKAGE_NAME}" \
org.opencontainers.image.authors="William Kennedy <bill@ardanlabs.com>" \
org.opencontainers.image.source="https://geeks-accelerator/oss/saas-starter-kit/example-project/cmd/${PACKAGE_PREFIX}${PACKAGE_NAME}" \
org.opencontainers.image.revision="${VCS_REF}" \
org.opencontainers.image.vendor="Ardan Labs"

View File

@ -13,19 +13,19 @@ import (
// User represents someone with access to our system.
type User struct {
ID string `db:"id" json:"id"`
Name string `db:"name" json:"name"`
Email string `db:"email" json:"email"`
ID string `json:"id"`
Name string `json:"name"`
Email string `json:"email"`
PasswordSalt string `db:"password_salt" json:"-"`
PasswordHash []byte `db:"password_hash" json:"-"`
PasswordReset sql.NullString `db:"password_reset" json:"-"`
PasswordSalt string `json:"-"`
PasswordHash []byte `json:"-"`
PasswordReset sql.NullString `json:"-"`
Timezone string `db:"timezone" json:"timezone"`
Timezone string `json:"timezone"`
CreatedAt time.Time `db:"created_at" json:"created_at"`
UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
ArchivedAt pq.NullTime `db:"archived_at" json:"archived_at"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
ArchivedAt pq.NullTime `json:"archived_at"`
}
// CreateUserRequest contains information needed to create a new User.
@ -75,14 +75,14 @@ type UserFindRequest struct {
// application. The status will allow users to be managed on by account with users
// being global to the application.
type UserAccount struct {
ID string `db:"id" json:"id"`
UserID string `db:"user_id" json:"user_id"`
AccountID string `db:"account_id" json:"account_id"`
Roles UserAccountRoles `db:"roles" json:"roles"`
Status UserAccountStatus `db:"status" json:"status"`
CreatedAt time.Time `db:"created_at" json:"created_at"`
UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
ArchivedAt pq.NullTime `db:"archived_at" json:"archived_at"`
ID string `json:"id"`
UserID string `json:"user_id"`
AccountID string `json:"account_id"`
Roles UserAccountRoles `json:"roles"`
Status UserAccountStatus `json:"status"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
ArchivedAt pq.NullTime `json:"archived_at"`
}
// AddAccountRequest defines the information is needed to associate a user to an

View File

@ -402,7 +402,7 @@ func Update(ctx context.Context, claims auth.Claims, dbConn *sqlx.DB, req Update
query := sqlbuilder.NewUpdateBuilder()
query.Update(usersTableName)
fields := []string{}
var fields []string
if req.Name != nil {
fields = append(fields, query.Assign("name", req.Name))
}

View File

@ -351,7 +351,7 @@ func UpdateAccount(ctx context.Context, claims auth.Claims, dbConn *sqlx.DB, req
return nil
}
// RemoveAccount...
// RemoveAccount soft deleted the user account from the database.
func RemoveAccount(ctx context.Context, claims auth.Claims, dbConn *sqlx.DB, req RemoveAccountRequest, now time.Time) error {
span, ctx := tracer.StartSpanFromContext(ctx, "internal.user.RemoveAccount")
defer span.Finish()
@ -402,7 +402,7 @@ func RemoveAccount(ctx context.Context, claims auth.Claims, dbConn *sqlx.DB, req
return nil
}
// DeleteAccount...
// DeleteAccount removes a user account from the database.
func DeleteAccount(ctx context.Context, claims auth.Claims, dbConn *sqlx.DB, req DeleteAccountRequest) error {
span, ctx := tracer.StartSpanFromContext(ctx, "internal.user.RemoveAccount")
defer span.Finish()