當前位置: 首頁>>代碼示例>>Golang>>正文


Golang base.Logger函數代碼示例

本文整理匯總了Golang中hypermind/core/base.Logger函數的典型用法代碼示例。如果您正苦於以下問題:Golang Logger函數的具體用法?Golang Logger怎麽用?Golang Logger使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Logger函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Upload

func Upload(w http.ResponseWriter, r *http.Request) {
	base.Logger().Infoln(request.GetRequestInfo(r))
	if r.Method == "GET" {
		token := r.Form.Get("token")
		t, _ := template.ParseFiles(request.GeneratePagePath("upload"))
		err := t.Execute(w, token)
		if err != nil {
			base.Logger().Errorln("PageWriteErr:", err)
		}
	} else {
		r.ParseMultipartForm(32 << 20)
		file, handler, err := r.FormFile("uploadfile")
		if err != nil {
			base.Logger().Errorln("UploadFileParsError:", err)
			return
		}
		defer file.Close()
		fmt.Fprintf(w, "%v", handler.Header)
		var buffer bytes.Buffer
		buffer.WriteString(os.TempDir())
		buffer.WriteString("/")
		buffer.WriteString(handler.Filename)
		tempFilePath := buffer.String()
		f, err := os.OpenFile(tempFilePath, os.O_WRONLY|os.O_CREATE, 0666)
		if err != nil {
			base.Logger().Errorln(err)
			return
		}
		defer f.Close()
		base.Logger().Infoln("Receive a file & save to %s ...\n", tempFilePath)
		io.Copy(f, file)
		go request.DeleteTempFile(time.Duration(time.Minute*5), tempFilePath)
	}
}
開發者ID:hyper-carrot,項目名稱:hypermind,代碼行數:34,代碼來源:controller.go

示例2: RequestDispatcher

func RequestDispatcher(w http.ResponseWriter, r *http.Request) {
	r.ParseForm()
	base.Logger().Infoln(request.GetRequestInfo(r))
	attrMap := request.GenerateBasicAttrMap(w, r)
	currentPage := r.FormValue("page")
	if len(currentPage) == 0 {
		currentPage = base.HOME_PAGE
	}
	pageRightsTag := attrMap[currentPage]
	if pageRightsTag != "true" {
		currentPage = base.HOME_PAGE
	}
	t := template.New("welcome page")
	t.Funcs(template.FuncMap{
		"equal":   request.SimpleEqual,
		"match":   request.MatchString,
		"allTrue": request.AllTrue,
	})
	t, err := t.ParseFiles(request.GeneratePagePath(currentPage),
		request.GeneratePagePath("common"),
		request.GeneratePagePath("navbar"))
	if err != nil {
		base.Logger().Errorln("ParseFilesErr:", err)
	}
	attrMap["currentPage"] = currentPage
	err = t.ExecuteTemplate(w, "page", attrMap)
	if err != nil {
		base.Logger().Errorln("ExecuteTemplateErr:", err)
	}
	recordPageAccessInfo(currentPage, attrMap[request.LOGIN_NAME_KEY], uint64(1))
}
開發者ID:hyper-carrot,項目名稱:hypermind,代碼行數:31,代碼來源:controller.go

示例3: GetCurrentAuthCode

func GetCurrentAuthCode() (string, error) {
	conn := dao.RedisPool.Get()
	defer conn.Close()
	values, err := redis.Values(conn.Do("LRANGE", dao.AUTH_CODE_KEY, 0, 0))
	if err != nil {
		return "", err
	}
	var currentAuthCode string
	if len(values) > 0 {
		var buffer bytes.Buffer
		value := values[0]
		valueBytes := value.([]byte)
		for _, v := range valueBytes {
			buffer.WriteByte(v)
		}
		currentAuthCode = buffer.String()
		base.Logger().Infof("Current Code: '%s'\n", currentAuthCode)
	} else {
		initialAuthCode := generateInitialAuthCode()
		base.Logger().Infof("Initial Auth Code: '%s'\n", initialAuthCode)
		err = pushAuthCode(initialAuthCode, conn)
		if err != nil {
			return "", err
		}
		currentAuthCode = initialAuthCode
	}
	return currentAuthCode, nil
}
開發者ID:hyper-carrot,項目名稱:hypermind,代碼行數:28,代碼來源:auth_code.go

示例4: Destroy

func (self *MySession) Destroy() (bool, error) {
	if len(self.key) == 0 || len(self.sessionId) == 0 {
		errorMsg := fmt.Sprintln("Uninitialized yet!")
		return false, errors.New(errorMsg)
	}
	base.Logger().Infof("Destroy session (key=%s)... \n", self.key)
	grantors, err := dao.GetHash(self.key, SESSION_GRANTORS_KEY)
	if err != nil {
		return false, err
	}
	_, err = dao.DelKey(self.key)
	if err != nil {
		return false, err
	}
	if len(grantors) > 0 {
		_, err = dao.DelHashField(SESSION_MAP_KEY, grantors)
		if err != nil {
			return false, err
		}
	}
	base.Logger().Infof("Delete session cookie (value=%s)...\n", self.sessionId)
	hmSessionCookie.Delete(SESSION_COOKIE_KEY, self.w)
	base.Logger().Infof("The session (key=%s) is destroyed. \n", self.key)
	return true, nil
}
開發者ID:hyper-carrot,項目名稱:hypermind,代碼行數:25,代碼來源:session.go

示例5: Register

func Register(w http.ResponseWriter, r *http.Request) {
	r.ParseForm()
	base.Logger().Infoln(request.GetRequestInfo(r))
	if r.Method == "GET" {
		attrMap := request.GenerateBasicAttrMap(w, r)
		encodedHint := r.FormValue("hint")
		if len(encodedHint) > 0 {
			hint := request.UrlDecoding(encodedHint)
			attrMap["hint"] = hint
		}
		t, _ := template.ParseFiles(request.GeneratePagePath("register"))
		err := t.Execute(w, attrMap)
		if err != nil {
			base.Logger().Errorln("PageWriteErr:", err)
		}
	} else {
		fieldMap, invalidFields := request.VerifyRegisterForm(r)
		base.Logger().Infoln("The field map:", fieldMap)
		if len(invalidFields) > 0 {
			hint := fmt.Sprintln("There are some invalid fields of '':", invalidFields, ".")
			base.Logger().Infoln(hint)
			encodedHint := request.UrlEncoding(hint)
			redirectUrl := "/register?hint=" + encodedHint
			http.Redirect(w, r, redirectUrl, http.StatusFound)
		} else {
			http.Redirect(w, r, "/", http.StatusFound)
		}
	}
}
開發者ID:hyper-carrot,項目名稱:hypermind,代碼行數:29,代碼來源:controller.go

示例6: DeleteTempFile

func DeleteTempFile(delay time.Duration, filePath string) (err error) {
	time.Sleep(delay)
	err = os.Remove(filePath)
	if err != nil {
		base.Logger().Errorf("Occur error when delete file '%s': %s\n", filePath, err)
	} else {
		base.Logger().Infof("The file '%s' is deleted.\n", filePath, err)
	}
	return
}
開發者ID:hyper-carrot,項目名稱:hypermind,代碼行數:10,代碼來源:request.go

示例7: init

func init() {
	newAuthCodeTriggerMap = make(map[string]NewAuthCodeTrigger)
	firstNewAuthCodeTrigger := func(newAuthCode string) {
		base.Logger().Infof("There has a new auth code '%s'.", newAuthCode)
	}
	AddNewAuthCodeTrigger("monitoring", firstNewAuthCodeTrigger)
}
開發者ID:hyper-carrot,項目名稱:hypermind,代碼行數:7,代碼來源:auth_code.go

示例8: GetSessionMap

func GetSessionMap(w http.ResponseWriter, r *http.Request) map[string]string {
	var sessionMap map[string]string
	hmSession, err := GetSession(w, r)
	if err != nil {
		base.Logger().Errorln("GetSessionError: %s\n", err)
		return sessionMap
	}
	if hmSession != nil {
		sessionMap, err = hmSession.GetAll()
		if err != nil {
			base.Logger().Errorln("SessionGetAllError: %s\n", err)
			return sessionMap
		}
	}
	return sessionMap
}
開發者ID:hyper-carrot,項目名稱:hypermind,代碼行數:16,代碼來源:request.go

示例9: VerifyAuthCode

func VerifyAuthCode(authCode string) (bool, error) {
	if len(authCode) == 0 {
		return false, nil
	}
	currentAuthCode, err := GetCurrentAuthCode()
	var pass bool
	if err == nil {
		pass = (currentAuthCode == strings.TrimSpace(authCode))
	}
	if pass {
		go func() {
			var newAuthCode string
			for {
				newAuthCode = generateAuthCode()
				if newAuthCode != currentAuthCode {
					break
				}
			}
			if len(newAuthCode) > 0 {
				conn := dao.RedisPool.Get()
				defer conn.Close()
				err = pushAuthCode(newAuthCode, conn)
				if err != nil {
					base.Logger().Errorf("New auth code pushing error: %s\n", err)
				}
			}
		}()
	}
	return pass, err
}
開發者ID:hyper-carrot,項目名稱:hypermind,代碼行數:30,代碼來源:auth_code.go

示例10: GenerateBasicAttrMap

func GenerateBasicAttrMap(w http.ResponseWriter, r *http.Request) map[string]string {
	attrMap := make(map[string]string)
	host, port := splitHostPort(r.Host)
	attrMap["serverAddr"] = host
	attrMap["serverPort"] = port
	for pageKey, page := range pageParameterMap {
		attrMap[pageKey] = page
	}
	hmSession, err := GetSession(w, r)
	if err != nil {
		base.Logger().Errorln("GetSessionError: %s\n", err)
	} else {
		var pageRights map[string]string
		var loginName string
		var groupName string
		if hmSession != nil {
			pageRights = getPageRights(hmSession)
			loginName = getLoginName(hmSession)
			groupName = getGroupName(hmSession)
		} else {
			pageRights = rights.GetGuestPageRights()
			loginName = ""
			groupName = ""
		}
		for p, pr := range pageRights {
			attrMap[p] = pr
		}
		attrMap[LOGIN_NAME_KEY] = loginName
		attrMap[GROUP_NAME_KEY] = groupName
	}
	return attrMap
}
開發者ID:hyper-carrot,項目名稱:hypermind,代碼行數:32,代碼來源:request.go

示例11: GetMatchedSession

func GetMatchedSession(w http.ResponseWriter, r *http.Request) (*MySession, error) {
	sessionId := hmSessionCookie.GetOne(SESSION_COOKIE_KEY, r)
	if len(sessionId) == 0 {
		warningMsg := fmt.Sprintf("Not found matched session! No session cookie!")
		base.Logger().Warnln(warningMsg)
		return nil, nil
	}
	sessionkey := generateSessionKey(sessionId)
	exists, err := dao.Exists(sessionkey)
	if err != nil {
		return nil, err
	}
	if !exists {
		warningMsg := fmt.Sprintf("Not found matched session! No session in storage! (sessionId=%s, sessionKey=%s)", sessionId, sessionkey)
		base.Logger().Warnln(warningMsg)
		return nil, nil
	}
	grantors, err := dao.GetHash(sessionkey, SESSION_GRANTORS_KEY)
	if err != nil {
		return nil, err
	}
	if len(grantors) == 0 {
		warningMsg := fmt.Sprintf("Not found grantor from session (sessionKey=%s, attribute=%s)!\n", sessionkey, SESSION_GRANTORS_KEY)
		base.Logger().Warnln(warningMsg)
		return nil, nil
	}
	groupName, err := dao.GetHash(sessionkey, SESSION_GROUP_KEY)
	if err != nil {
		return nil, err
	}
	if len(groupName) == 0 {
		warningMsg := fmt.Sprintf("Not found group name from session (sessionKey=%s, attribute=%s)!\n", sessionkey, SESSION_GROUP_KEY)
		base.Logger().Warnln(warningMsg)
		return nil, err
	}
	servivalSecondsLiterals, err := dao.GetHash(sessionkey, SESSION_SURVIVAL_SECONDS_KEY)
	if err != nil {
		return nil, err
	}
	if len(servivalSecondsLiterals) == 0 {
		warningMsg := fmt.Sprintf("Not found session servival seconds. Use default value '0'. (sessionKey=%s, attribute=%s)!\n", sessionkey, SESSION_SURVIVAL_SECONDS_KEY)
		base.Logger().Warnln(warningMsg)
		return nil, err
	}
	hmSession := &MySession{key: sessionkey, sessionId: sessionId, w: w, r: r}
	return hmSession, nil
}
開發者ID:hyper-carrot,項目名稱:hypermind,代碼行數:47,代碼來源:session.go

示例12: GetRequestInfo

func GetRequestInfo(r *http.Request) string {
	requestInfo := RequestInfo{Form: r.Form, Method: r.Method, Path: r.URL.Path, Scheme: r.URL.Scheme}
	b, err := json.Marshal(requestInfo)
	if err != nil {
		base.Logger().Errorln("JsonMarshalError:", err)
	}
	return string(b)
}
開發者ID:hyper-carrot,項目名稱:hypermind,代碼行數:8,代碼來源:request.go

示例13: getGroupName

func getGroupName(hmSession *session.MySession) string {
	if hmSession == nil {
		return ""
	}
	groupName, err := hmSession.Get(session.SESSION_GROUP_KEY)
	if err != nil {
		base.Logger().Errorln("SessionGetError (field=%s): %s\n", session.SESSION_GROUP_KEY, err)
		return ""
	}
	return groupName
}
開發者ID:hyper-carrot,項目名稱:hypermind,代碼行數:11,代碼來源:request.go

示例14: recordPageAccessInfo

func recordPageAccessInfo(pageName string, visitor string, number uint64) bool {
	var result bool
	done, err := statistics.AddPageAccessRecord(pageName, visitor, number)
	if err != nil {
		base.Logger().Errorf("Adding page access record error: %s (pageName=%s, visitor=%s, number=%d)\n", err, pageName, visitor, number)
		result = false
	} else {
		result = done
	}
	return result
}
開發者ID:hyper-carrot,項目名稱:hypermind,代碼行數:11,代碼來源:common.go

示例15: pushResponse

func pushResponse(bufrw *bufio.ReadWriter, authCode string) bool {
	_, err := bufrw.Write([]byte(authCode))
	if err == nil {
		err = bufrw.Flush()
	}
	if err != nil {
		base.Logger().Errorf("PushAuthCodeError: %s\n", err)
		return false
	}
	return true
}
開發者ID:hyper-carrot,項目名稱:hypermind,代碼行數:11,代碼來源:common.go


注:本文中的hypermind/core/base.Logger函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。