Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
117 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,4 @@ | ||
*.8 | ||
*.6 | ||
*.out | ||
*.a |
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,10 @@ | ||
include $(GOROOT)/src/Make.$(GOARCH) | ||
|
||
TARG=goldorak | ||
GOFILES=\ | ||
action.go\ | ||
config.go\ | ||
goldorak.go\ | ||
model.go\ | ||
|
||
include $(GOROOT)/src/Make.pkg |
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 @@ | ||
package goldorak | ||
|
||
import ( | ||
"json" | ||
"io/ioutil" | ||
"log" | ||
) | ||
|
||
var config map[string]string | ||
|
||
func ReadConfig(filename string) { | ||
contents, err := ioutil.ReadFile(filename) | ||
if err != nil { | ||
log.Exitf("Impossible to read %s", filename) | ||
} | ||
data, err := json.Decode(string(contents)) | ||
if err != nil { | ||
log.Exitf("Can't parse %s as JSON", filename) | ||
} | ||
config = map[string]string{ } | ||
for key, value := range data.(map[string]interface{ }) { | ||
config[key] = value.(string) | ||
} | ||
} | ||
|
||
func GetConfig(key string) string { | ||
return config[key]; | ||
} | ||
|
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,16 @@ | ||
package goldorak | ||
|
||
import ( | ||
"web" | ||
) | ||
|
||
func Initialize() { | ||
ReadConfig("config.json") | ||
} | ||
|
||
func Start() { | ||
addr := GetConfig("interface") + ":" + GetConfig("port") | ||
web.SetStaticDir(GetConfig("docroot")) | ||
web.Run(addr) | ||
} | ||
|
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,45 @@ | ||
package goldorak | ||
|
||
import ( | ||
"redis" | ||
"strconv" | ||
"strings" | ||
) | ||
|
||
type Model struct { | ||
db int | ||
client redis.Client | ||
name string | ||
} | ||
|
||
const keySeparator = ":" | ||
|
||
func NewModel(name string) *Model { | ||
fn := GetConfig("appname") + keySeparator + name | ||
db := GetConfig("db") | ||
m := new(Model) | ||
m.db, _ = strconv.Atoi(db) | ||
s := redis.DefaultSpec().Db(m.db) | ||
// TODO if e != nil ... | ||
m.name = fn | ||
m.client, _ = redis.NewSynchClientWithSpec(s) | ||
// TODO | ||
// if e != nil { log.Stderr ("failed to create the client", e); return "failed" } | ||
return m | ||
} | ||
|
||
func (m *Model) FullKey(key string) string { | ||
return m.name + keySeparator + key | ||
} | ||
|
||
func (m *Model) Get(key string) string { | ||
value, _ := m.client.Get(m.FullKey(key)) | ||
// TODO | ||
// if e!= nil { log.Stderr ("error on Get", e); return "failed 2" } | ||
return string(value); | ||
} | ||
|
||
func (m *Model) Set(key string, value string) { | ||
m.client.Set(m.FullKey(key), strings.Bytes(value)) | ||
} | ||
|
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,13 @@ | ||
package goldorak | ||
|
||
import ( | ||
"web" | ||
) | ||
|
||
// TODO what about POST/PUT/DELETE? | ||
func Get(route string, handler interface{}) { | ||
web.Get(route, handler) | ||
} | ||
|
||
// TODO func Restful() | ||
|