func InvocationFromBase64(invoc g.Invocation) (g.Invocation, error) { enc := base64.StdEncoding var err error cmd, err := enc.DecodeString(invoc.Command) user, err := enc.DecodeString(invoc.User) host, err := enc.DecodeString(invoc.Host) shell, err := enc.DecodeString(invoc.Shell) dir, err := enc.DecodeString(invoc.Directory) tags := make([][]byte, len(invoc.Tags)) for i, t := range invoc.Tags { tags[i], err = enc.DecodeString(t) } if err != nil { return invoc, err } invoc.Command = string(cmd) invoc.User = string(user) invoc.Host = string(host) invoc.Shell = string(shell) invoc.Directory = string(dir) for i, t := range tags { invoc.Tags[i] = string(t) } return invoc, nil }
// queryInvocations is a common handler for implementing paging over Invocations func queryInvocations(rows *sql.Rows, pageSize int) (result gohst.Invocations, err error) { defer rows.Close() var tmp gohst.Invocation var tags string inc := 0 if pageSize == 0 { inc = -1 } for rows.Next() && inc < pageSize { err = rows.Scan(&tmp.Id, &tmp.ExitCode, &tmp.Timestamp, &tmp.Host, &tmp.User, &tmp.Shell, &tmp.Directory, &tmp.Command, &tags) if err != nil { log.Println(err) return } tmp.Tags = strings.Split(tags[1:len(tags)-1], ", ") result = append(result, tmp) if pageSize > 0 { inc++ } } err = rows.Err() if err != nil { log.Println(err) } return }
func InvocationToBase64(invoc g.Invocation) g.Invocation { enc := base64.StdEncoding invoc.Command = enc.EncodeToString([]byte(invoc.Command)) invoc.User = enc.EncodeToString([]byte(invoc.User)) invoc.Host = enc.EncodeToString([]byte(invoc.Host)) invoc.Shell = enc.EncodeToString([]byte(invoc.Shell)) invoc.Directory = enc.EncodeToString([]byte(invoc.Directory)) for i, t := range invoc.Tags { invoc.Tags[i] = enc.EncodeToString([]byte(t)) } return invoc }