-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement boilerplate code for http API
- Loading branch information
Showing
32 changed files
with
1,838 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name: Go Test | ||
|
||
on: | ||
push: | ||
|
||
jobs: | ||
|
||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: 1.21 | ||
|
||
- name: Build | ||
run: go build -v ./... | ||
|
||
- name: Test | ||
run: go test -v ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Created by https://www.toptal.com/developers/gitignore/api/go | ||
# Edit at https://www.toptal.com/developers/gitignore?templates=go | ||
|
||
### Go ### | ||
# If you prefer the allow list template instead of the deny list, see community template: | ||
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore | ||
# | ||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Test binary, built with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
# Dependency directories (remove the comment below to include it) | ||
# vendor/ | ||
|
||
# Go workspace file | ||
go.work | ||
|
||
# End of https://www.toptal.com/developers/gitignore/api/go | ||
|
||
.envrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Thomas Li | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package app | ||
|
||
import ( | ||
"github.com/STommydx/FolioForge/config" | ||
"github.com/STommydx/FolioForge/db" | ||
"github.com/STommydx/FolioForge/healthz" | ||
"github.com/STommydx/FolioForge/http" | ||
"github.com/STommydx/FolioForge/logger" | ||
"go.uber.org/fx" | ||
) | ||
|
||
func New() *fx.App { | ||
app := fx.New( | ||
fx.Provide(config.NewAppConfigFromEnv), | ||
logger.Module, | ||
http.Module, | ||
healthz.Module, | ||
db.Module, | ||
) | ||
return app | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package cmd | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var rootCmd = &cobra.Command{ | ||
Use: "FolioForge", | ||
Short: "API toolkit designed to streamline the management and presentation of your professional portfolio", | ||
Long: `FolioForge is an API toolkit designed to streamline the management and presentation of your professional portfolio. With FolioForge, you can easily update your experience, projects, and skills through its intuitive CRUD endpoints. Plus, it seamlessly generates a polished resume based on your data and a provided LaTeX template, empowering you to showcase your qualifications with confidence.`, | ||
} | ||
|
||
func Execute() { | ||
err := rootCmd.Execute() | ||
if err != nil { | ||
os.Exit(1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/STommydx/FolioForge/app" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var serveCmd = &cobra.Command{ | ||
Use: "serve", | ||
Short: "Start the API server", | ||
Long: `Start the API server.`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
mainApp := app.New() | ||
mainApp.Run() | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(serveCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
var workerCmd = &cobra.Command{ | ||
Use: "worker", | ||
Short: "Start the worker", | ||
Long: `Start the worker.`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
fmt.Println("worker called") | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(workerCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package config | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/STommydx/FolioForge/db" | ||
"github.com/STommydx/FolioForge/http" | ||
"github.com/STommydx/FolioForge/logger" | ||
"github.com/sethvargo/go-envconfig" | ||
"go.uber.org/fx" | ||
) | ||
|
||
type AppConfig struct { | ||
fx.Out | ||
Postgres *db.Config `env:", prefix=POSTGRES_"` | ||
Logger *logger.Config `env:", prefix=LOG_"` | ||
Api *http.Config `env:", prefix=API_"` | ||
} | ||
|
||
func NewAppConfigFromEnv() (AppConfig, error) { | ||
ctx := context.Background() | ||
config := AppConfig{} | ||
if err := envconfig.Process(ctx, &config); err != nil { | ||
return config, err | ||
} | ||
return config, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
data "external_schema" "gorm" { | ||
program = [ | ||
"go", | ||
"run", | ||
"-mod=mod", | ||
"ariga.io/atlas-provider-gorm", | ||
"load", | ||
"--path", ".", | ||
"--dialect", "postgres", // | postgres | sqlite | sqlserver | ||
] | ||
} | ||
|
||
env "gorm" { | ||
src = data.external_schema.gorm.url | ||
dev = "docker://postgres/15/dev" | ||
migration { | ||
dir = "file://migrations" | ||
} | ||
format { | ||
migrate { | ||
diff = "{{ sql . \" \" }}" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package db | ||
|
||
import ( | ||
"fmt" | ||
|
||
"gorm.io/driver/postgres" | ||
"gorm.io/gorm" | ||
) | ||
|
||
type Config struct { | ||
Host string `env:"HOST, required"` | ||
Port string `env:"PORT, default=5432"` | ||
Username string `env:"USER, required"` | ||
Password string `env:"PASSWORD, required"` | ||
Database string `env:"DB, default=folioforge"` | ||
} | ||
|
||
func NewPostgresDB(config *Config) (*gorm.DB, error) { | ||
dsn := fmt.Sprintf("host=%s user=%s password=%s dbname=%s sslmode=disable", | ||
config.Host, | ||
config.Username, | ||
config.Password, | ||
config.Database, | ||
) | ||
db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return db, nil | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
-- Create "profiles" table | ||
CREATE TABLE "public"."profiles" ( | ||
"id" bytea NOT NULL, | ||
"profile_name" text NULL, | ||
"first_name" text NULL, | ||
"last_name" text NULL, | ||
"email" text NULL, | ||
"phone" text NULL, | ||
"created_at" timestamptz NULL, | ||
"updated_at" timestamptz NULL, | ||
PRIMARY KEY ("id") | ||
); | ||
-- Create index "idx_profiles_profile_name" to table: "profiles" | ||
CREATE UNIQUE INDEX "idx_profiles_profile_name" ON "public"."profiles" ("profile_name"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
h1:0t0ZkOqmdPLmosv0/2YxWuzQ5gVwLH0NYA0vLMwVQDk= | ||
20240220070657.sql h1:Oh11EPLob5cZLq9goyJ5i5psPiG2xdV8PE665t29y/Q= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package db | ||
|
||
import ( | ||
"time" | ||
|
||
_ "ariga.io/atlas-provider-gorm/gormschema" | ||
"github.com/oklog/ulid/v2" | ||
) | ||
|
||
type Profile struct { | ||
ID ulid.ULID `gorm:"primaryKey"` | ||
ProfileName string `gorm:"uniqueIndex"` | ||
FirstName string | ||
LastName string | ||
Email string | ||
Phone string | ||
CreatedAt time.Time | ||
UpdatedAt time.Time | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package db | ||
|
||
import "go.uber.org/fx" | ||
|
||
var Module = fx.Options( | ||
fx.Provide(NewPostgresDB), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
version: '3' | ||
|
||
services: | ||
postgresql: | ||
image: postgres:15 | ||
ports: | ||
- "5432:5432" | ||
environment: | ||
POSTGRES_USER: folioforge | ||
POSTGRES_PASSWORD: folioforge | ||
POSTGRES_DB: folioforge |
Oops, something went wrong.