summaryrefslogtreecommitdiffstats
path: root/model
diff options
context:
space:
mode:
author=Corey Hulen <corey@hulen.com>2015-09-16 19:59:57 -0700
committer=Corey Hulen <corey@hulen.com>2015-09-16 19:59:57 -0700
commitabda39b6523f2563d4663036f13ad1c24dac161e (patch)
tree3573d568f220c8e778f872c0fb501a280bb87468 /model
parent1e7f7852ad09d97c8d33012192bd1ff418881b8f (diff)
downloadchat-abda39b6523f2563d4663036f13ad1c24dac161e.tar.gz
chat-abda39b6523f2563d4663036f13ad1c24dac161e.tar.bz2
chat-abda39b6523f2563d4663036f13ad1c24dac161e.zip
Adding database schema version
Diffstat (limited to 'model')
-rw-r--r--model/system.go34
-rw-r--r--model/system_test.go19
2 files changed, 53 insertions, 0 deletions
diff --git a/model/system.go b/model/system.go
new file mode 100644
index 000000000..c79391cca
--- /dev/null
+++ b/model/system.go
@@ -0,0 +1,34 @@
+// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+package model
+
+import (
+ "encoding/json"
+ "io"
+)
+
+type System struct {
+ Name string `json:"name"`
+ Value string `json:"value"`
+}
+
+func (o *System) ToJson() string {
+ b, err := json.Marshal(o)
+ if err != nil {
+ return ""
+ } else {
+ return string(b)
+ }
+}
+
+func SystemFromJson(data io.Reader) *System {
+ decoder := json.NewDecoder(data)
+ var o System
+ err := decoder.Decode(&o)
+ if err == nil {
+ return &o
+ } else {
+ return nil
+ }
+}
diff --git a/model/system_test.go b/model/system_test.go
new file mode 100644
index 000000000..14ba0db2e
--- /dev/null
+++ b/model/system_test.go
@@ -0,0 +1,19 @@
+// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+package model
+
+import (
+ "strings"
+ "testing"
+)
+
+func TestSystemJson(t *testing.T) {
+ system := System{Name: "test", Value: NewId()}
+ json := system.ToJson()
+ result := SystemFromJson(strings.NewReader(json))
+
+ if result.Name != "test" {
+ t.Fatal("Ids do not match")
+ }
+}