Skip to content

Commit

Permalink
Rewrite for Goyave v5
Browse files Browse the repository at this point in the history
  • Loading branch information
System-Glitch committed May 10, 2024
1 parent 35786f1 commit 29fd154
Show file tree
Hide file tree
Showing 52 changed files with 1,152 additions and 1,909 deletions.
25 changes: 10 additions & 15 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,28 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go: [1.16, 1.17]
go: ["1.22"]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go }}
- name: Run tests
env:
DB_HOST: 127.0.0.1
run: |
echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
sudo /etc/init.d/mysql start
while ! mysqladmin ping --silent; do
sleep 1
done
sudo mysql -proot -e 'CREATE DATABASE goyave CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;'
sudo mysql -proot -e 'CREATE USER "goyave"@"%" IDENTIFIED BY "secret"'
sudo mysql -proot -e 'GRANT ALL PRIVILEGES ON goyave.* TO "goyave"@"%"'
go test -v -race ./...
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.22"
cache: false
- name: Run lint
uses: golangci/golangci-lint-action@v2
uses: golangci/golangci-lint-action@v6
with:
version: v1.45
version: v1.58
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@
config.json

.idea/
.vscode/
.vscode/

.storage/avatars/*
!.storage/avatars/.gitkeep
28 changes: 18 additions & 10 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
run:
skip-dirs:
- .github

linters-settings:
gocyclo:
min-complexity: 25
min-complexity: 15
gofmt:
simplify: true
misspell:
locale: US
govet:
disable:
- shadow
- nilness
- fieldalignment
enable-all: true

linters:
Expand All @@ -22,15 +16,29 @@ linters:
- revive
- gocyclo
- misspell
- bodyclose
- govet
- deadcode
disable:
- unused
- errcheck
- exportloopref
- gosimple
- ineffassign
- staticcheck
- testifylint
- bodyclose
disable-all: false
fast: false

issues:
exclude-use-default: false
max-issues-per-linter: 0
max-same-issues: 0
exclude-dirs:
- .github
exclude:
- should have a package comment
- for error assertions use require
- should have comment or be unexported
exclude-rules:
- path: _test\.go
linters:
- gocyclo
Empty file added .storage/avatars/.gitkeep
Empty file.
17 changes: 0 additions & 17 deletions Dockerfile

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 Jérémy LAMBERT (SystemGlitch)
Copyright (c) 2024 Jérémy LAMBERT (SystemGlitch)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
89 changes: 12 additions & 77 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,89 +1,24 @@
<p align="center">
<img src="https://raw.githubusercontent.com/System-Glitch/goyave/master/resources/img/logo/goyave_text.png" alt="Goyave Logo" width="550"/>
<img src="https://raw.githubusercontent.com/go-goyave/goyave/master/resources/img/logo/goyave_text.png#gh-light-mode-only" alt="Goyave Logo" width="550"/>
<img src="https://raw.githubusercontent.com/go-goyave/goyave/master/resources/img/logo/goyave_text_dark.png#gh-dark-mode-only" alt="Goyave Logo" width="550"/>
</p>

## Goyave Blog Example

![https://github.com/go-goyave/goyave-blog-example/actions](https://github.com/go-goyave/goyave-blog-example/workflows/Test/badge.svg)

This codebase was created to demonstrate a fully fledged fullstack application built with **[Goyave](https://github.com/System-Glitch/goyave)** including CRUD operations, authentication, routing, pagination, and more.
This example project was created to demonstrate a simple application built with **[Goyave](https://github.com/go-goyave/goyave)** including CRUD operations, authentication, routing, pagination, and more. With this application, users can register, login and write blog posts (articles) or read the other user's ones.

## Getting Started
## Running the project

### Requirements
First, make your own configuration for your local environment.

- Go 1.16+
- Go modules
- Copy `config.example.json` to `config.json`.
- Start the database container with `docker-compose up`.
- Run migrations with [dbmate](https://github.com/amacneil/dbmate): `dbmate -u postgres://dbuser:[email protected]:5432/blog?sslmode=disable -d ./database/migrations --no-dump-schema migrate`
- Run `go run main.go` in your project's directory to start the server. If you want to seed your database with random records use the `-seed` flag: `go run main.go -seed`. Users will all be created with the following password: `p4ssW0rd_`

### Directory structure
## Resources

```
.
├── database
│   ├── model // ORM models
│   | └── ...
│   └── seeder // Generators for database testing
│   └── ...
├── http
│   ├── controller // Business logic of the application
│   │ └── ...
│   ├── middleware // Logic executed before or after controllers
│   │ └── ...
│   ├── validation
│   │   └── validation.go // Custom validation rules
│   └── route
│   └── route.go // Routes definition
├── resources
│   └── lang
│      └── en-US // Overrides to the default language lines
│      ├── fields.json
│      ├── locale.json
│      └── rules.json
├── test // Functional tests
| └── ...
|
├── .gitignore
├── .golangci.yml // Settings for the Golangci-lint linter
├── config.example.json // Example config for local development
├── config.test.json // Config file used for tests
├── go.mod
└── main.go // Application entrypoint
```

### Running the project

First, make your own configuration for your local environment. You can copy `config.example.json` to `config.json`.

Run `go run main.go` in your project's directory to start the server.

**Using docker:**

```
docker-compose up
```

**Run tests with docker:**

```
docker-compose -f docker-compose.test.yml up --abort-on-container-exit
```

**Database seeding:**

If `app.environment` is set to `localhost` in the config and if the database is empty (no record in the users table), the seeders will be executed and a random dataset will be generated and inserted into the database.

## Learning Goyave

The Goyave framework has an extensive documentation covering in-depth subjects and teaching you how to run a project using Goyave from setup to deployment.

<a href="https://goyave.dev/guide/installation"><h3 align="center">Read the documentation</h3></a>

<a href="https://pkg.go.dev/goyave.dev/goyave/v4"><h3 align="center">pkg.go.dev</h3></a>

## License

This example project is MIT Licensed. Copyright © 2020 Jérémy LAMBERT (SystemGlitch)

The Goyave framework is MIT Licensed. Copyright © 2019 Jérémy LAMBERT (SystemGlitch)
- [Documentation](https://goyave.dev)
- [go.pkg.dev](https://pkg.go.dev/goyave.dev/goyave/v5)
50 changes: 33 additions & 17 deletions config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,52 @@
"name": "goyave-blog-example",
"environment": "localhost",
"debug": true,
"defaultLanguage": "en-US",
"bcryptCost": 10
"defaultLanguage": "en-US"
},
"server": {
"host": "0.0.0.0",
"maintenance": false,
"protocol": "http",
"host": "127.0.0.1",
"domain": "",
"port": 8080,
"httpsPort": 443,
"timeout": 10,
"maxUploadSize": 10
"writeTimeout": 10,
"readTimeout": 10,
"readHeaderTimeout": 10,
"idleTimeout": 20,
"websocketCloseTimeout": 10,
"maxUploadSize": 10.0,
"proxy": {
"protocol": "http",
"host": "",
"port": 80,
"base": ""
}
},
"database": {
"connection": "mysql",
"host": "mariadb",
"port": 3306,
"name": "goyave",
"username": "goyave",
"connection": "postgres",
"host": "127.0.0.1",
"port": 5432,
"name": "blog",
"username": "dbuser",
"password": "secret",
"options": "charset=utf8mb4&collation=utf8mb4_general_ci&parseTime=true&loc=Local",
"options": "sslmode=disable application_name=goyave-blog-example",
"maxOpenConnections": 20,
"maxIdleConnections": 20,
"maxLifetime": 300,
"autoMigrate": true
"defaultReadQueryTimeout": 20000,
"defaultWriteQueryTimeout": 40000,
"config": {
"skipDefaultTransaction": false,
"dryRun": false,
"prepareStmt": true,
"disableNestedTransaction": false,
"allowGlobalUpdate": false,
"disableAutomaticPing": false,
"disableForeignKeyConstraintWhenMigrating": false
}
},
"auth": {
"jwt": {
"expiry": 3600,
"secret": "1C4C304DACBEC13CC975A3708CFAF6AED0A478573C1C0D7EBFF0E7E8530C06B7"
"secret": "jwt-secret",
"expiry": 3000
}
}
}
58 changes: 37 additions & 21 deletions config.test.json
Original file line number Diff line number Diff line change
@@ -1,38 +1,54 @@
{
"app": {
"name": "goyave-blog-example",
"environment": "test",
"debug": false,
"defaultLanguage": "en-US",
"bcryptCost": 10
"name": "goyave.dev/template",
"environment": "localhost",
"debug": true,
"defaultLanguage": "en-US"
},
"server": {
"host": "127.0.0.1",
"maintenance": false,
"protocol": "http",
"domain": "",
"port": 8080,
"httpsPort": 443,
"timeout": 10,
"maxUploadSize": 10
"port": 0,
"writeTimeout": 10,
"readTimeout": 10,
"readHeaderTimeout": 10,
"idleTimeout": 20,
"websocketCloseTimeout": 10,
"maxUploadSize": 10.0,
"proxy": {
"protocol": "http",
"host": "",
"port": 80,
"base": ""
}
},
"database": {
"connection": "mysql",
"host": "${DB_HOST}",
"port": 3306,
"name": "goyave",
"username": "goyave",
"password": "secret",
"options": "charset=utf8mb4&collation=utf8mb4_general_ci&parseTime=true&loc=Local",
"connection": "none",
"host": "127.0.0.1",
"port": 0,
"name": "",
"username": "",
"password": "",
"options": "",
"maxOpenConnections": 20,
"maxIdleConnections": 20,
"maxLifetime": 300,
"autoMigrate": true
"defaultReadQueryTimeout": 20000,
"defaultWriteQueryTimeout": 40000,
"config": {
"skipDefaultTransaction": false,
"dryRun": false,
"prepareStmt": true,
"disableNestedTransaction": false,
"allowGlobalUpdate": false,
"disableAutomaticPing": true,
"disableForeignKeyConstraintWhenMigrating": false
}
},
"auth": {
"jwt": {
"expiry": 3600,
"secret": "1C4C304DACBEC13CC975A3708CFAF6AED0A478573C1C0D7EBFF0E7E8530C06B7"
"secret": "jwt-secret",
"expiry": 3000
}
}
}
Loading

0 comments on commit 29fd154

Please sign in to comment.