Skip to content

Commit 9cd1511

Browse files
authored
Merge pull request #21 from go-gorf/20-add-gorf-types-mod-for-common-types
Gorf types module
2 parents 7706e08 + 88f4085 commit 9cd1511

File tree

15 files changed

+197
-17
lines changed

15 files changed

+197
-17
lines changed

app.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package gorf
33
import (
44
"fmt"
55
"github.com/gin-gonic/gin"
6+
"log"
67
)
78

89
// Apps array of all registered apps
@@ -49,7 +50,7 @@ func SetupApps() {
4950
for _, app := range Apps {
5051
err := app.Setup()
5152
if err != nil {
52-
panic("Unable to configure apps")
53+
log.Fatal("unable to configure apps, ", err.Error())
5354
}
5455
}
5556
}

backends/dynamodbi/db.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ type DynamoDB struct {
99
func (d *DynamoDB) Get(dest interface{}, key string) error {
1010
return nil
1111
}
12+
func (d *DynamoDB) GetUser(dest interface{}, id string) error {
13+
return nil
14+
}
1215

1316
func (d *DynamoDB) Filter(dest interface{}, conds ...interface{}) error {
1417
return nil

backends/gormi/db.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,22 @@ type GormDB struct {
99
}
1010

1111
func (d *GormDB) Get(dest interface{}, key string) error {
12+
//TODO:implement
13+
return nil
14+
}
15+
16+
func (d *GormDB) GetUser(dest interface{}, id string) error {
17+
//TODO:implement
1218
return nil
1319
}
1420

1521
func (d *GormDB) Filter(dest interface{}, conds ...interface{}) error {
22+
//TODO:implement
1623
return nil
1724
}
1825

1926
func (d *GormDB) AutoMigrate(dst ...interface{}) error {
27+
//TODO:implement
2028
return d.DB.Migrator().AutoMigrate(dst...)
2129
}
2230

backends/gormi/sqlite.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ type GormSqliteBackend struct {
1010
Name string
1111
}
1212

13+
func NewSqliteBackend(name string) *GormSqliteBackend {
14+
return &GormSqliteBackend{Name: name}
15+
}
16+
1317
func (b *GormSqliteBackend) Connect() (gorf.Db, error) {
1418
db, err := gorm.Open(sqlite.Open(b.Name), &gorm.Config{})
1519
if err != nil {

common/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/go-gorf/gorf/common
2+
3+
go 1.20

common/user.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package common
2+
3+
type LoginInput struct {
4+
Email string `json:"email" binding:"required"`
5+
Password string `json:"password" binding:"required"`
6+
}

database.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type Db interface {
2828
AutoMigrate(dst ...interface{}) error
2929
First(dest interface{}, conds ...interface{}) error
3030
Create(value interface{}) error
31+
GetUser(dest interface{}, id string) error
3132
}
3233

3334
type DbBackend interface {
@@ -45,7 +46,7 @@ func InitializeDatabase() error {
4546

4647
DB, err = Settings.DbBackends.Connect()
4748
if err != nil {
48-
return errors.New("Unable to initialise the database")
49+
return errors.New("unable to initialise the database")
4950
}
5051
return nil
5152
}

errors.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package gorf
22

33
import (
4+
"errors"
45
"github.com/gin-gonic/gin"
5-
"net/http"
66
)
77

88
type Err struct {
@@ -11,6 +11,20 @@ type Err struct {
1111
status int
1212
}
1313

14+
func NewErr(msg string, status int, err error) *Err {
15+
var e error
16+
if err != nil {
17+
e = err
18+
} else {
19+
e = errors.New(msg)
20+
}
21+
return &Err{
22+
Msg: msg,
23+
Er: e,
24+
status: status,
25+
}
26+
}
27+
1428
func (e *Err) Response() gin.H {
1529
return gin.H{
1630
"Message": e.Msg,
@@ -22,8 +36,3 @@ func (e *Err) Response() gin.H {
2236
func (e *Err) Error() string {
2337
return e.Er.Error()
2438
}
25-
26-
func BadRequest(ctx *gin.Context, msg string, err error) {
27-
e := &Err{msg, err, http.StatusBadRequest}
28-
ctx.JSON(http.StatusBadRequest, e.Response())
29-
}

examples/admin/settings.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
)
88

99
var apps = []gorf.App{
10-
&admin.App,
10+
&admin.AdminApp,
1111
}
1212

1313
func LoadSettings() {

examples/auth/go.mod

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,22 @@ module github.com/go-gorf/gorf/example/auth
22

33
go 1.20
44

5-
65
require (
6+
github.com/caarlos0/env/v8 v8.0.0
77
github.com/gin-gonic/gin v1.9.1
8-
github.com/go-gorf/auth v0.0.8
9-
github.com/go-gorf/gorf v0.0.13
8+
github.com/go-gorf/auth v0.0.9
9+
github.com/go-gorf/gorf v0.0.14
1010
)
1111

12+
replace github.com/go-gorf/gorf => ../../
13+
14+
replace github.com/go-gorf/gorf/common => ../../common
15+
16+
replace github.com/go-gorf/gorf/backends/gormi => ../../backends/gormi
17+
18+
//remove
19+
//replace github.com/go-gorf/auth => ../../../auth
20+
1221
require (
1322
github.com/aws/aws-sdk-go-v2 v1.18.0 // indirect
1423
github.com/aws/aws-sdk-go-v2/config v1.18.25 // indirect
@@ -24,22 +33,35 @@ require (
2433
github.com/aws/aws-sdk-go-v2/service/sts v1.19.0 // indirect
2534
github.com/aws/smithy-go v1.13.5 // indirect
2635
github.com/bytedance/sonic v1.9.1 // indirect
27-
github.com/caarlos0/env/v8 v8.0.0 // indirect
2836
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
37+
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
2938
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
3039
github.com/gin-contrib/sse v0.1.0 // indirect
40+
github.com/go-gorf/gorf/backends/gormi v0.0.0-20230611221909-7706e082ab74 // indirect
41+
github.com/go-gorf/gorf/common v0.0.0-00010101000000-000000000000 // indirect
3142
github.com/go-playground/locales v0.14.1 // indirect
3243
github.com/go-playground/universal-translator v0.18.1 // indirect
3344
github.com/go-playground/validator/v10 v10.14.0 // indirect
3445
github.com/goccy/go-json v0.10.2 // indirect
46+
github.com/golang-jwt/jwt/v5 v5.0.0 // indirect
47+
github.com/jinzhu/inflection v1.0.0 // indirect
48+
github.com/jinzhu/now v1.1.5 // indirect
3549
github.com/json-iterator/go v1.1.12 // indirect
3650
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
3751
github.com/kr/text v0.2.0 // indirect
3852
github.com/leodido/go-urn v1.2.4 // indirect
53+
github.com/lestrrat-go/blackmagic v1.0.1 // indirect
54+
github.com/lestrrat-go/httpcc v1.0.1 // indirect
55+
github.com/lestrrat-go/httprc v1.0.4 // indirect
56+
github.com/lestrrat-go/iter v1.0.2 // indirect
57+
github.com/lestrrat-go/jwx/v2 v2.0.11 // indirect
58+
github.com/lestrrat-go/option v1.0.1 // indirect
3959
github.com/mattn/go-isatty v0.0.19 // indirect
60+
github.com/mattn/go-sqlite3 v1.14.16 // indirect
4061
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
4162
github.com/modern-go/reflect2 v1.0.2 // indirect
4263
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
64+
github.com/segmentio/asm v1.2.0 // indirect
4365
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
4466
github.com/ugorji/go/codec v1.2.11 // indirect
4567
golang.org/x/arch v0.3.0 // indirect
@@ -49,4 +71,6 @@ require (
4971
golang.org/x/text v0.9.0 // indirect
5072
google.golang.org/protobuf v1.30.0 // indirect
5173
gopkg.in/yaml.v3 v3.0.1 // indirect
74+
gorm.io/driver/sqlite v1.5.1 // indirect
75+
gorm.io/gorm v1.25.1 // indirect
5276
)

0 commit comments

Comments
 (0)