Example #1
0
func CommandFromBase64(cmd g.Command) (g.Command, error) {
	enc := base64.StdEncoding
	c, err := enc.DecodeString(string(cmd))
	if err != nil {
		return cmd, nil
	}
	return g.Command(c), nil
}
Example #2
0
func DecryptCommands(cmds g.Commands, key []byte) (g.Commands, error) {
	assoc := make([][]byte, 0)
	for i, c := range cmds {
		com, err := siv.Decrypt(key, []byte(c), assoc)
		if err != nil {
			return nil, err
		}
		cmds[i] = g.Command(com)
	}
	return cmds, nil
}
Example #3
0
// queryCommands is a common handler for implementing paging over Commands
func queryCommands(rows *sql.Rows, pageSize int) (result gohst.Commands, err error) {
	defer rows.Close()
	var c string
	inc := 0
	if pageSize == 0 {
		inc = -1
	}
	for rows.Next() && inc < pageSize {
		err = rows.Scan(&c)
		if err != nil {
			return
		}
		result = append(result, gohst.Command(c))
		if pageSize > 0 {
			inc++
		}
	}
	err = rows.Err()
	if err != nil {
		log.Println(err)
	}
	return
}