in server/table_handler.go [140:193]
func handleListCmd(w http.ResponseWriter, t *tableCmdReq) error {
var err error
var cond string
var args = make([]interface{}, 0)
cond, args = state.AddSQLCond(cond, args, "AND", "cluster", "=", t.Cluster)
cond, args = state.AddSQLCond(cond, args, "AND", "service", "=", t.Service)
cond, args = state.AddSQLCond(cond, args, "AND", "db", "=", t.DB)
cond, args = state.AddSQLCond(cond, args, "AND", "table_name", "=", t.Table)
cond, args = state.AddSQLCond(cond, args, "AND", "input", "=", t.Input)
cond, args = state.AddSQLCond(cond, args, "AND", "output", "=", t.Output)
if t.Version != 0 {
cond, args = state.AddSQLCond(cond, args, "AND", "version", "=", fmt.Sprintf("%d", t.Version))
}
cond, args = addFilter(cond, args, []string{"cluster", "service", "db", "table_name", "input", "output", "output_format"}, t.Filter)
if t.Offset != 0 || t.Limit != 0 {
if t.Limit == 0 && t.Offset != 0 {
t.Limit = int64((^uint64(0)) >> 1) //MaxInt
}
cond += fmt.Sprintf(" LIMIT %v,%v", t.Offset, t.Limit)
}
var rows state.Type
if t.Type == "state" {
rows, err = state.GetCond(cond, args...)
} else {
rows, err = state.GetRegCond(cond, args...)
}
if err == nil {
var resp []byte
for _, v := range rows {
if v.Cluster == "" {
v.Cluster = "*"
}
if v.DB == "" {
v.DB = "*"
}
var b []byte
if b, err = json.Marshal(&tableListResponse{Cluster: v.Cluster, Service: v.Service, DB: v.DB, Table: v.Table, Input: v.Input, Output: v.Output, Version: v.Version, OutputFormat: v.OutputFormat, SnapshottedAt: v.SnapshottedAt, NeedSnapshot: v.NeedSnapshot, Params: v.ParamsRaw, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt}); err != nil {
break
}
resp = append(resp, b...)
resp = append(resp, '\n')
}
if err == nil {
_, err = w.Write(resp)
}
}
return err
}