Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
# Logs and databases #
######################
*.log
*.sql
*.sqlite

# OS generated files #
Expand Down
20 changes: 20 additions & 0 deletions .golangci.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"linters": {
"disable-all": true,
"enable": [
"govet",
"golint",
"goimports",
"misspell",
"ineffassign",
"gofmt",
"whitespace"
]
},
"run": {
"skip-files": [
"/zz_generated_"
],
"deadline": "5m"
}
}
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,33 @@ TODO
## License ##

This library was originally developed by Reaction Engineering International for several internal projects. It is now being made available under the MIT license (see LICENSE.txt).

## Mocking ##
You can update or generate all mocks for testing with:
```
go generate ./...
```


## Testing ##
The Framework uses the builtin testing capabilities in go

## DB Migrations ##
All db migrations are handled using sql-migrate found at https://github.com/rubenv/sql-migrate. When using this as a library, you can act upon the migrations
```go
db, err := sql.Open("postgres", dbString) //"root:P1p3sh0p@tcp(:3306)/localDB?parseTime=true"
if err != nil{
log.Fatal(err)
}
defer db.Close()

restLibMigrations := migrations.Postgres()

migrate.SetTable("restlib_migrations")
n, err := migrate.Exec(db, "postgres", restLibMigrations, migrate.Up)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Applied %d migrations!\n", n)

```
104 changes: 0 additions & 104 deletions cache/ObjectMemCache.go

This file was deleted.

6 changes: 4 additions & 2 deletions cache/ObjectCache.go → cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

package cache

type ObjectCache interface {
Get(key string, item interface{})
//go:generate mockgen -destination=../mocks/mock_cache.go -package=mocks github.com/reaction-eng/restlib/cache Cache

type Cache interface {
Get(key string, item interface{}) bool

Set(key string, item interface{}) error

Expand Down
66 changes: 66 additions & 0 deletions cache/memory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright 2019 Reaction Engineering International. All rights reserved.
// Use of this source code is governed by the MIT license in the file LICENSE.txt.

package cache

//go:generate mockgen -destination=../mocks/mock_memory.go -package=mocks github.com/reaction-eng/restlib/cache RawMemoryCache

import (
"encoding/json"
)

type Memory struct {
rawMemoryCache RawMemoryCache
}

type RawMemoryCache interface {
Get(k string) (interface{}, bool)
SetDefault(k string, x interface{})
}

func NewMemory(rawMemoryCache RawMemoryCache) *Memory {
objectMemCache := Memory{
rawMemoryCache,
}

return &objectMemCache
}

func (memory *Memory) Set(key string, item interface{}) error {
//Now save it
memory.rawMemoryCache.SetDefault(key, item)
return nil
}

func (memory *Memory) SetString(key string, value string) {
//Now save it
memory.rawMemoryCache.SetDefault(key, value)
}

func (memory *Memory) Get(key string, returnItem interface{}) bool {
item, found := memory.rawMemoryCache.Get(key)

if found {
//Convert to json
jsonByte, err := json.Marshal(item)

if err != nil {
return false
}

//Now restore back
json.Unmarshal(jsonByte, &returnItem)
return true
} else {
return false
}
}

func (memory *Memory) GetString(key string) (string, bool) {
item, found := memory.rawMemoryCache.Get(key)

if found {
return item.(string), true
}
return "", false
}
Loading