예제 #1
0
파일: items.go 프로젝트: webx-top/webx
func (a *DB) Dsn() string {
	var dsn string
	switch a.Engine {
	case `mysql`:
		var host string
		if strings.HasPrefix(a.Host, `unix:`) {
			host = "unix(" + strings.TrimPrefix(a.Host, `unix:`) + ")"
		} else {
			if a.Port == `` {
				a.Port = "3306"
			}
			host = "tcp(" + a.Host + ":" + a.Port + ")"
		}
		dsn = com.UrlEncode(a.User) + ":" + com.UrlEncode(a.Pass) + "@" + host + "/" + a.Name + "?charset=" + a.Charset
	case `mymysql`: //tcp:localhost:3306*gotest/root/root
		var host string
		if strings.HasPrefix(a.Host, `unix:`) {
			host = a.Host
		} else {
			if a.Port == `` {
				a.Port = "3306"
			}
			host = "tcp:" + a.Host + ":" + a.Port
		}
		dsn = host + "*" + a.Name + "/" + com.UrlEncode(a.User) + "/" + com.UrlEncode(a.Pass)
	default:
		panic(a.Engine + ` is not supported.`)
	}
	return dsn
}
예제 #2
0
파일: context.go 프로젝트: webx-top/webx
func (c *Context) SetCookie(key, val string, args ...interface{}) {
	val = com.UrlEncode(val)
	cookie := c.Cookie(key, val)
	switch len(args) {
	case 5:
		httpOnly, _ := args[4].(bool)
		cookie.HttpOnly(httpOnly)
		fallthrough
	case 4:
		secure, _ := args[3].(bool)
		cookie.Secure(secure)
		fallthrough
	case 3:
		domain, _ := args[2].(string)
		cookie.Domain(domain)
		fallthrough
	case 2:
		path, _ := args[1].(string)
		cookie.Path(path)
		fallthrough
	case 1:
		var liftTime int64
		switch args[0].(type) {
		case int:
			liftTime = int64(args[0].(int))
		case int64:
			liftTime = args[0].(int64)
		case time.Duration:
			liftTime = int64(args[0].(time.Duration))
		}
		cookie.Expires(liftTime)
	}
	cookie.Send(c)
}