Пример #1
0
// get cookie's secret from session or create
func (c *Controller) getCookieSecret() string {
	cscret := c.GetSession(COOKIE_SECRET)
	if cscret != nil && len(cscret.(string)) == COOKIE_SECRET_LEN {
		return cscret.(string)
	} else {
		s := lib.RandomString(COOKIE_SECRET_LEN)
		c.SetSession(COOKIE_SECRET, s)
		return s
	}
}
Пример #2
0
	"github.com/ckeyer/commons/lib"
	"os"
	"strconv"
	"strings"
)

var (
	rtype string

	start = flag.Int("start", 0, "set start of rand number")
	end   = flag.Int("end", 100, "set end of rand number")

	randMap = map[string]randHandle{
		"s": func(l int) string {
			fmt.Println("...")
			return lib.RandomString(l)
		},
		"n": func(l int) string {
			ns := make([]string, 0, l)
			for i := 0; i < l; i++ {
				ns = append(ns, fmt.Sprint(lib.RandomInt(*start, *end)))
			}
			return strings.Join(ns, ", ")
		},
	}
)

type randHandle func(l int) string

func init() {
	flag.Parse()