README ¶
GoLang Server
---
title: Dependency Tree
---
flowchart LR
cmd
subgraph internal
server_go[/server.go\]
app
controllers
models
views
controllers --> server_go
views --> controllers
app --> controllers
app --> server_go
models --> controllers
models --> app
models --> views
end
subgraph pkg
imgbb
tsp
end
server_go --> cmd
app --> cmd
pkg --> internal
Development install
1. Dependencies
1.1. Please install the following:
1.2. Install the advised vscode extensions.
These extensions will popup as advised extensions
1.3. Install the golang extension dependencies
- Press
ctrl
+p
(MacOS:command
+p
) - Paste
>Go: Install/Update Tools
into text input - Select all options
- click OK
2. Start database and mailhog via docker
make docker-start
3. Setup config files
Copy /server/config.example.yml
to /server/config.dev.yml
Some values are obfuscated how to add these are explained below
3.1. Add stripe dev keys
This is required for payment calls, if you are not working on those calls these steps are not needed
- Create a stripe account
- Download and install the stripe cli https://stripe.com/docs/stripe-cli
- From https://dashboard.stripe.com/test/apikeys
- Copy secret key to
stripe_secret_key
in/server/config.yml
- Copy publishable key to
VITE_STRIPE_PUBLIC_KEY
in/frontend/.env
- Copy secret key to
- Go to webhooks and click Add an endpoint
- Set Endpoint url
http://localhost:8080/v1/payment/webhook
- Click add endpoint
- Set Endpoint url
3.2 Add database password
You must do this for the server to run properly.
Copy the value of MYSQL_PASSWORD
found in /server/docker/docker-compose.yml
, use the password to fill in db_pass
in /server/config.dev.yml
3.3 Copy to test config
Copy /server/config.dev.yml
to /server/config.test.yml
This enables tests to use the same database.
4. Start server
make start
5. Generate fake data (optional)
If you want you can create some fake data to use in your development environment. To do so run this command:
make generate-fake-data
Then setup some default users, a user for each permission role. Run the following in your database client of choice:
6. Setup Rest client
To document, test and use the server independently, Postman is to be used.
6.1. Install Postman
Install one of the Postman Rest client options here:
- app: https://www.postman.com/downloads/
- browser agent: https://www.postman.com/downloads/postman-agent/
- cli: https://learning.postman.com/docs/postman-cli/postman-cli-installation/
6.2. Use project in postman
Here is the link to the postman collection: https://www.postman.com/the-clothing-loop/workspace/the-clothing-loop/overview
Be warned that everything saved is publicly available if you want to save, remove the sensitive data beforehand or use an environment variable
Commands
Start as dev
make start
Build for VPS
make build-server
Build for Shared Hosting
This is an attempt to use shared hosting, but has never been properly tested.
make build-server-fcgi
Run tests
make test
Run docker
This is to create a test environment It includes handy environments to test:
- database queries
- email smtp test server (TODO)
make docker-start
And to stop the docker containers
make docker-stop
Lint
Although the golang.go
vscode extension should lint your code for you, there is also a command as well:
make lint
Setting up authentication in Postman
Variable | Type | Example | Description |
---|---|---|---|
base | default | http://localhost:8084 | Base server url |
token | secret | ********************* | Login, in a browser and find the token cookie |
userUID | default | e896d087-5dd0-44fa-a549-2ead33a63d7a | User UID |
chainUID | default | 48ca9112-912a-43b4-a8bc-16dcd79f383d | Chain UID |
- Here's how to find cookies from the website: Chromium: https://superuser.com/a/1114501 Firefox: https://firefox-source-docs.mozilla.org/devtools-user/storage_inspector/index.html
- Select the cookie named
token
and copy its value - Paste the value into Postman
- Make sure that the
userUID
is from the account you logged in with - If you want to send api requests that have a higher authentication level;
- AuthState3AdminChainUser & AuthState2UserOfChain: you need to set the
chainUID
to a loop that will relate to the user (seeuser_chains
table) and if need be, haveuser_chains.is_chain_admin
set to True. - AuthState4RootUser: you need to set the
users.is_root_admin
database cell to True.
- AuthState3AdminChainUser & AuthState2UserOfChain: you need to set the