Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
86ff949eae | ||
|
8476e37499 | ||
|
aad9cdfaf5 | ||
|
3738ba689e | ||
|
a833823ad6 | ||
|
de4a217c5f | ||
|
c4e83d06b9 | ||
|
51da24be9b | ||
|
e497f4d2f0 |
@ -19,7 +19,7 @@ fine with getting your hands dirty, but I plan on having it ready to go for more
|
|||||||
- Config file handling
|
- Config file handling
|
||||||
- Scheduled tasks
|
- Scheduled tasks
|
||||||
- Entire website compiles into a single binary (~10mb) (excluding env.json)
|
- Entire website compiles into a single binary (~10mb) (excluding env.json)
|
||||||
- Minimal dependencies (just standard library, postgres driver, and experimental package for bcrypt)
|
- Minimal dependencies (just standard library, postgres driver, and x/crypto for bcrypt)
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
@ -59,7 +59,7 @@ fine with getting your hands dirty, but I plan on having it ready to go for more
|
|||||||
### License and disclaimer 😤
|
### License and disclaimer 😤
|
||||||
|
|
||||||
- You are free to use this project under the terms of the MIT license. See LICENSE for more details.
|
- You are free to use this project under the terms of the MIT license. See LICENSE for more details.
|
||||||
- You and you alone are responsible for the security and everything else regarding your application.
|
- You are responsible for the security and everything else regarding your application.
|
||||||
- It is not required, but I ask that when you use this project you give me credit by linking to this repository.
|
- It is not required, but I ask that when you use this project you give me credit by linking to this repository.
|
||||||
- I also ask that when releasing self-hosted or other end-user applications that you release it under
|
- I also ask that when releasing self-hosted or other end-user applications that you release it under
|
||||||
the [GPLv3](https://www.gnu.org/licenses/gpl-3.0.html) license. This too is not required, but I would appreciate it.
|
the [GPLv3](https://www.gnu.org/licenses/gpl-3.0.html) license. This too is not required, but I would appreciate it.
|
@ -9,7 +9,8 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Migrate given a dummy object of any type, it will create a table with the same name as the type and create columns with the same name as the fields of the object
|
// Migrate given a dummy object of any type, it will create a table with the same name
|
||||||
|
// as the type and create columns with the same name as the fields of the object
|
||||||
func Migrate(app *app.App, anyStruct interface{}) error {
|
func Migrate(app *app.App, anyStruct interface{}) error {
|
||||||
valueOfStruct := reflect.ValueOf(anyStruct)
|
valueOfStruct := reflect.ValueOf(anyStruct)
|
||||||
typeOfStruct := valueOfStruct.Type()
|
typeOfStruct := valueOfStruct.Type()
|
||||||
@ -23,10 +24,15 @@ func Migrate(app *app.App, anyStruct interface{}) error {
|
|||||||
for i := 0; i < valueOfStruct.NumField(); i++ {
|
for i := 0; i < valueOfStruct.NumField(); i++ {
|
||||||
fieldType := typeOfStruct.Field(i)
|
fieldType := typeOfStruct.Field(i)
|
||||||
fieldName := fieldType.Name
|
fieldName := fieldType.Name
|
||||||
if fieldName != "Id" && fieldName != "id" {
|
|
||||||
err := createColumn(app, tableName, fieldName, fieldType.Type.Name())
|
// Create column if dummy for migration is NOT zero value
|
||||||
if err != nil {
|
fieldValue := valueOfStruct.Field(i).Interface()
|
||||||
return err
|
if !reflect.ValueOf(fieldValue).IsZero() {
|
||||||
|
if fieldName != "Id" && fieldName != "id" {
|
||||||
|
err := createColumn(app, tableName, fieldName, fieldType.Type.Name())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
4
go.mod
4
go.mod
@ -1,8 +1,8 @@
|
|||||||
module GoWeb
|
module GoWeb
|
||||||
|
|
||||||
go 1.21
|
go 1.22
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/lib/pq v1.10.9
|
github.com/lib/pq v1.10.9
|
||||||
golang.org/x/crypto v0.17.0
|
golang.org/x/crypto v0.24.0
|
||||||
)
|
)
|
||||||
|
4
go.sum
4
go.sum
@ -1,4 +1,4 @@
|
|||||||
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
|
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
|
||||||
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
||||||
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
|
golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI=
|
||||||
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
|
golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM=
|
||||||
|
@ -17,7 +17,7 @@ type Session struct {
|
|||||||
CreatedAt time.Time
|
CreatedAt time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
const sessionColumnsNoId = "\"UserId\", \"AuthToken\",\"RememberMe\", \"CreatedAt\""
|
const sessionColumnsNoId = "\"UserId\", \"AuthToken\", \"RememberMe\", \"CreatedAt\""
|
||||||
const sessionColumns = "\"Id\", " + sessionColumnsNoId
|
const sessionColumns = "\"Id\", " + sessionColumnsNoId
|
||||||
const sessionTable = "public.\"Session\""
|
const sessionTable = "public.\"Session\""
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user