Adding database schema version

Этот коммит содержится в:
=Corey Hulen
2015-09-16 19:59:57 -07:00
родитель 1e7f7852ad
Коммит abda39b652
7 изменённых файлов: 222 добавлений и 3 удалений

34
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
}
}

19
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")
}
}