func (r *Request) model(model interface{}, query string) {
	r.success(modelResponse{Model: model, Query: query})
}
model sends a successful model response for the get request.
package res
import (
	"encoding/json"
	"errors"
	"fmt"
	"runtime/debug"
	"strconv"
	"time"
	nats "github.com/nats-io/nats.go"
)
const (
	RequestTypeAccess = "access"
	RequestTypeGet    = "get"
	RequestTypeCall   = "call"
	RequestTypeAuth   = "auth"
)
type Request struct {
	resource
	rtype   string
	method  string
	msg     *nats.Msg
	replied bool  
	cid        string
	params     json.RawMessage
	token      json.RawMessage
	header     map[string][]string
	host       string
	remoteAddr string
	uri        string
}
type AccessRequest interface {
	Resource
	CID() string
	RawToken() json.RawMessage
	ParseToken(interface{})
	Access(get bool, call string)
	AccessDenied()
	AccessGranted()
	NotFound()
	InvalidQuery(message string)
	Error(err error)
	Timeout(d time.Duration)
}
type ModelRequest interface {
	Resource
	Model(model interface{})
	QueryModel(model interface{}, query string)
	NotFound()
	InvalidQuery(message string)
	Error(err error)
	Timeout(d time.Duration)
	ForValue() bool
}
type CollectionRequest interface {
	Resource
	Collection(collection interface{})
	QueryCollection(collection interface{}, query string)
	NotFound()
	InvalidQuery(message string)
	Error(err error)
	Timeout(d time.Duration)
	ForValue() bool
}
type GetRequest interface {
	Resource
	Model(model interface{})
	QueryModel(model interface{}, query string)
	Collection(collection interface{})
	QueryCollection(collection interface{}, query string)
	NotFound()
	InvalidQuery(message string)
	Error(err error)
	Timeout(d time.Duration)
	ForValue() bool
}
type CallRequest interface {
	Resource
	Method() string
	CID() string
	RawParams() json.RawMessage
	RawToken() json.RawMessage
	ParseParams(interface{})
	ParseToken(interface{})
	OK(result interface{})
	Resource(rid string)
	NotFound()
	MethodNotFound()
	InvalidParams(message string)
	InvalidQuery(message string)
	Error(err error)
	Timeout(d time.Duration)
}
type NewRequest interface {
	Resource
	CID() string
	RawParams() json.RawMessage
	RawToken() json.RawMessage
	ParseParams(interface{})
	ParseToken(interface{})
	New(rid Ref)
	NotFound()
	MethodNotFound()
	InvalidParams(message string)
	InvalidQuery(message string)
	Error(err error)
	Timeout(d time.Duration)
}
type AuthRequest interface {
	Resource
	Method() string
	CID() string
	RawParams() json.RawMessage
	RawToken() json.RawMessage
	ParseParams(interface{})
	ParseToken(interface{})
	Header() map[string][]string
	Host() string
	RemoteAddr() string
	URI() string
	OK(result interface{})
	Resource(rid string)
	NotFound()
	MethodNotFound()
	InvalidParams(message string)
	InvalidQuery(message string)
	Error(err error)
	Timeout(d time.Duration)
	TokenEvent(t interface{})
}
var (
	responseAccessDenied    = []byte(`{"error":{"code":"system.accessDenied","message":"Access denied"}}`)
	responseInternalError   = []byte(`{"error":{"code":"system.internalError","message":"Internal error"}}`)
	responseNotFound        = []byte(`{"error":{"code":"system.notFound","message":"Not found"}}`)
	responseMethodNotFound  = []byte(`{"error":{"code":"system.methodNotFound","message":"Method not found"}}`)
	responseInvalidParams   = []byte(`{"error":{"code":"system.invalidParams","message":"Invalid parameters"}}`)
	responseInvalidQuery    = []byte(`{"error":{"code":"system.invalidQuery","message":"Invalid query"}}`)
	responseMissingResponse = []byte(`{"error":{"code":"system.internalError","message":"Internal error: missing response"}}`)
	responseMissingQuery    = []byte(`{"error":{"code":"system.internalError","message":"Internal error: missing query"}}`)
	responseAccessGranted   = []byte(`{"result":{"get":true,"call":"*"}}`)
	responseNoQueryEvents   = []byte(`{"result":{"events":[]}}`)
	responseSuccess         = []byte(`{"result":null}`)
)
var (
	AccessGranted AccessHandler = func(r AccessRequest) {
		r.AccessGranted()
	}
	AccessDenied AccessHandler = func(r AccessRequest) {
		r.AccessDenied()
	}
)
func (r *Request) Type() string {
	return r.rtype
}
func (r *Request) Method() string {
	return r.method
}
func (r *Request) CID() string {
	return r.cid
}
func (r *Request) RawParams() json.RawMessage {
	return r.params
}
func (r *Request) RawToken() json.RawMessage {
	return r.token
}
func (r *Request) Header() map[string][]string {
	return r.header
}
func (r *Request) Host() string {
	return r.host
}
func (r *Request) RemoteAddr() string {
	return r.remoteAddr
}
func (r *Request) URI() string {
	return r.uri
}
func (r *Request) OK(result interface{}) {
	if result == nil {
		r.reply(responseSuccess)
	} else {
		r.success(result)
	}
}
func (r *Request) Resource(rid string) {
	ref := Ref(rid)
	if !ref.IsValid() {
		panic("res: invalid resource ID: " + rid)
	}
	data, err := json.Marshal(resourceResponse{Resource: ref})
	if err != nil {
		r.error(ToError(err))
		return
	}
	r.reply(data)
}
func (r *Request) Error(err error) {
	r.error(ToError(err))
}
func (r *Request) NotFound() {
	r.reply(responseNotFound)
}
func (r *Request) MethodNotFound() {
	r.reply(responseMethodNotFound)
}
func (r *Request) InvalidParams(message string) {
	if message == "" {
		r.reply(responseInvalidParams)
	} else {
		r.error(&Error{Code: CodeInvalidParams, Message: message})
	}
}
func (r *Request) InvalidQuery(message string) {
	if message == "" {
		r.reply(responseInvalidQuery)
	} else {
		r.error(&Error{Code: CodeInvalidQuery, Message: message})
	}
}
func (r *Request) Access(get bool, call string) {
	if !get && call == "" {
		r.reply(responseAccessDenied)
	} else {
		r.success(accessResponse{Get: get, Call: call})
	}
}
func (r *Request) AccessDenied() {
	r.reply(responseAccessDenied)
}
func (r *Request) AccessGranted() {
	r.reply(responseAccessGranted)
}
func (r *Request) Model(model interface{}) {
	r.model(model, "")
}
func (r *Request) QueryModel(model interface{}, query string) {
	r.model(model, query)
}