Beispiel #1
0
package model

import "github.com/jmjoy/http-api-tester/app"

var HistoryModel = &historyModel{
	Model: app.NewModel("history"),
	key:   "history",
}

type historyModel struct {
	*app.Model
	key string
}

func (this *historyModel) GetAll() (datas []Data, err error) {
	has, err := this.Model.Get(this.key, &datas)
	if err != nil {
		return
	}

	if !has {
		datas = []Data{}
		return
	}

	return
}

func (this *historyModel) Insert(data Data) (err error) {
	var datas []Data
	datas, err = this.GetAll()
Beispiel #2
0
package model

import (
	"github.com/jmjoy/http-api-tester/app"
)

var BookmarkModel = &bookmarkModel{
	Model:    app.NewModel("bookmark"),
	selected: "selected",
}

type bookmarkModel struct {
	*app.Model
	selected string
}

func (this *bookmarkModel) GetCurrentKey() (name string, has bool, err error) {
	has, err = this.Get(this.selected, &name)
	return
}

func (this *bookmarkModel) GetCurrent() (bookmark Bookmark, err error) {
	name, has, err := this.GetCurrentKey()
	if err != nil {
		return
	}
	if !has {
		return Bookmark{
			Name: BOOKMARK_DEFAULT_NAME,
			Data: DataDefault(),
		}, nil