本文整理匯總了Golang中com/papersns/global.CloseSession函數的典型用法代碼示例。如果您正苦於以下問題:Golang CloseSession函數的具體用法?Golang CloseSession怎麽用?Golang CloseSession使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了CloseSession函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: MenuList
func (c App) MenuList() revel.Result {
sessionId := global.GetSessionId()
defer global.CloseSession(sessionId)
_, db := global.GetConnection(sessionId)
menuResultLi := []map[string]interface{}{}
err := db.C("Menu").Find(nil).Sort("level").All(&menuResultLi)
if err != nil {
panic(err)
}
menuLi := []map[string]interface{}{}
for _, item := range menuResultLi {
level := fmt.Sprint(item["level"])
if len(level) == 3 {
menuLi = append(menuLi, item)
subMenuLi := []map[string]interface{}{}
for _, subItem := range menuResultLi {
subLevel := fmt.Sprint(subItem["level"])
if len(subLevel) == 6 && subLevel[0:3] == level {
subMenuLi = append(subMenuLi, subItem)
}
}
item["subMenuLi"] = subMenuLi
}
}
result := map[string]interface{}{
"menuLi": menuLi,
}
return c.Render(result)
}
示例2: Login
func (c Hjq) Login() revel.Result {
if strings.ToLower(c.Request.Method) == "get" {
//c.Response.ContentType = "text/html; charset=utf-8"
return c.Render()
}
username := c.Params.Get("username")
password := c.Params.Get("password")
hash := sha1.New()
_, err := io.WriteString(hash, password)
if err != nil {
panic(err)
}
encryPassword := fmt.Sprintf("%x", hash.Sum(nil))
sessionId := global.GetSessionId()
defer global.CloseSession(sessionId)
session, _ := global.GetConnection(sessionId)
qb := QuerySupport{}
user, found := qb.FindByMapWithSession(session, "SysUser", map[string]interface{}{
"A.type": 1,
"A.name": username,
"A.password": encryPassword,
})
if !found {
c.Response.ContentType = "text/plain; charset=utf-8"
return c.RenderText("用戶名密碼錯誤")
}
c.Session["adminUserId"] = fmt.Sprint(user["id"])
c.Session["userId"] = fmt.Sprint(user["id"])
return c.Redirect("/console/[email protected]=LastSessionData&cookie=false")
}
示例3: Relation
func (c Console) Relation() revel.Result {
sessionId := global.GetSessionId()
global.SetGlobalAttr(sessionId, "userId", c.Session["userId"])
global.SetGlobalAttr(sessionId, "adminUserId", c.Session["adminUserId"])
defer global.CloseSession(sessionId)
selectorId := c.Params.Get("selectorId")
id := c.Params.Get("id")
templateManager := TemplateManager{}
relationLi := []map[string]interface{}{
map[string]interface{}{
"selectorId": selectorId,
"relationId": id,
},
}
relationBo := templateManager.GetRelationBo(sessionId, relationLi)
var result interface{} = nil
var url interface{} = nil
if relationBo[selectorId] != nil {
selRelationBo := relationBo[selectorId].(map[string]interface{})
if selRelationBo[id] != nil {
result = selRelationBo[id]
url = selRelationBo["url"]
}
}
c.Response.ContentType = "application/json; charset=utf-8"
return c.RenderJson(map[string]interface{}{
"result": result,
"url": url,
})
}
示例4: RCopyDataCommon
func (c BaseDataAction) RCopyDataCommon() ModelRenderVO {
sessionId := global.GetSessionId()
global.SetGlobalAttr(sessionId, "userId", c.Session["userId"])
global.SetGlobalAttr(sessionId, "adminUserId", c.Session["adminUserId"])
defer global.CloseSession(sessionId)
defer c.RRollbackTxn(sessionId)
userId, err := strconv.Atoi(c.Session["userId"])
if err != nil {
panic(err)
}
dataSourceModelId := c.Params.Get("dataSourceModelId")
formTemplateId := c.Params.Get("formTemplateId")
strId := c.Params.Get("id")
id, err := strconv.Atoi(strId)
if err != nil {
panic(err)
}
querySupport := QuerySupport{}
queryMap := map[string]interface{}{
"_id": id,
}
templateManager := TemplateManager{}
formTemplate := templateManager.GetFormTemplate(formTemplateId)
permissionSupport := PermissionSupport{}
permissionQueryDict := permissionSupport.GetPermissionQueryDict(sessionId, formTemplate.Security)
for k, v := range permissionQueryDict {
queryMap[k] = v
}
modelTemplateFactory := ModelTemplateFactory{}
dataSource := modelTemplateFactory.GetDataSource(dataSourceModelId)
collectionName := modelTemplateFactory.GetCollectionName(dataSource)
srcBo, found := querySupport.FindByMap(collectionName, queryMap)
if !found {
panic("CopyData, dataSouceModelId=" + dataSourceModelId + ", id=" + strId + " not found")
}
modelTemplateFactory.ConvertDataType(dataSource, &srcBo)
c.RActionSupport.RBeforeCopyData(sessionId, dataSource, formTemplate, srcBo)
dataSource, bo := modelTemplateFactory.GetCopyInstance(dataSourceModelId, srcBo)
c.RActionSupport.RAfterCopyData(sessionId, dataSource, formTemplate, &bo)
columnModelData := templateManager.GetColumnModelDataForFormTemplate(sessionId, formTemplate, bo)
bo = columnModelData["bo"].(map[string]interface{})
relationBo := columnModelData["relationBo"].(map[string]interface{})
modelTemplateFactory.ClearReverseRelation(&dataSource)
c.CommitTxn(sessionId)
return ModelRenderVO{
UserId: userId,
Bo: bo,
RelationBo: relationBo,
DataSource: dataSource,
FormTemplate: formTemplate,
}
}
示例5: GetProgramDictionary
func (o ProgramDictionaryManager) GetProgramDictionary(code string) map[string]interface{} {
mongoDBFactory := mongo.GetInstance()
session, db := mongoDBFactory.GetConnection()
defer session.Close()
sessionId := global.GetSessionId()
defer global.CloseSession(sessionId)
return o.GetProgramDictionaryBySession(sessionId, db, code)
}
示例6: GetLayer
func (o LayerManager) GetLayer(code string) map[string]interface{} {
connectionFactory := mongo.GetInstance()
session, db := connectionFactory.GetConnection()
defer session.Close()
sessionId := global.GetSessionId()
defer global.CloseSession(sessionId)
return o.GetLayerBySession(sessionId, db, code)
}
示例7: SchemaQueryParameterTest
func (c Component) SchemaQueryParameterTest() revel.Result {
sessionId := global.GetSessionId()
defer global.CloseSession(sessionId)
file, err := os.Open(`/home/hongjinqiu/goworkspace/src/finance/app/src/com/papersns/component/schema/SysUser.xml`)
defer file.Close()
if err != nil {
fmt.Printf("error: %v", err)
return c.Render(err)
}
data, err := ioutil.ReadAll(file)
if err != nil {
fmt.Printf("error: %v", err)
return c.Render(err)
}
listTemplate := ListTemplate{}
err = xml.Unmarshal(data, &listTemplate)
if err != nil {
fmt.Printf("error: %v", err)
return c.Render(err)
}
// 1.query data,
// from data-provider
// from query-parameters
templateManager := TemplateManager{}
paramMap := map[string]string{}
{
// paramMap["nick"] = "abc"
// paramMap["dept_id"] = "2"
// paramMap["type"] = "0,1,2.5,3.5,abc"
// paramMap["createTimeBegin"] = "2013-05-07"
// paramMap["createTimeEnd"] = "2014-06-03"
}
pageNo := 1
pageSize := 10
queryResult := templateManager.QueryDataForListTemplate(sessionId, &listTemplate, paramMap, pageNo, pageSize)
items := queryResult["items"].([]interface{})
if len(items) > 1 {
queryResult["items"] = items[:1]
}
jsonByte, err := json.MarshalIndent(queryResult, "", "\t")
if err != nil {
panic(err)
}
c.Response.Status = http.StatusOK
c.Response.ContentType = "text/plain; charset=utf-8"
return c.RenderText(string(jsonByte))
}
示例8: GetColumnModelDataForListTemplate
func (c Component) GetColumnModelDataForListTemplate() revel.Result {
sessionId := global.GetSessionId()
defer global.CloseSession(sessionId)
file, err := os.Open(`/home/hongjinqiu/goworkspace/src/finance/app/src/com/papersns/component/schema/SysUser.xml`)
defer file.Close()
if err != nil {
fmt.Printf("error: %v", err)
return c.Render(err)
}
data, err := ioutil.ReadAll(file)
if err != nil {
fmt.Printf("error: %v", err)
return c.Render(err)
}
listTemplate := ListTemplate{}
err = xml.Unmarshal(data, &listTemplate)
if err != nil {
fmt.Printf("error: %v", err)
return c.Render(err)
}
templateManager := TemplateManager{}
paramMap := map[string]string{}
pageNo := 1
pageSize := 10
queryResult := templateManager.QueryDataForListTemplate(sessionId, &listTemplate, paramMap, pageNo, pageSize)
items := queryResult["items"].([]interface{})
if len(items) > 1 {
queryResult["items"] = items[:1]
}
columnResult := templateManager.GetColumnModelDataForListTemplate(sessionId, listTemplate, items[:1])
resultItems := columnResult["items"].([]interface{})
jsonByte, err := json.MarshalIndent(resultItems, "", "\t")
if err != nil {
panic(err)
}
c.Response.Status = http.StatusOK
c.Response.ContentType = "text/plain; charset=utf-8"
return c.RenderText(string(jsonByte))
}
示例9: StepTest
func (c App) StepTest() revel.Result {
sessionId := global.GetSessionId()
defer global.CloseSession(sessionId)
_, db := global.GetConnection(sessionId)
stepLi := []interface{}{}
err := db.C("SysStep").Find(map[string]interface{}{
"A.sysUnitId": 1,
"A.status": 1,
}).Sort("A.type").All(&stepLi)
if err != nil {
panic(err)
}
c.RenderArgs["result"] = map[string]interface{}{
"stepLi": stepLi,
}
//c.Response.ContentType = "text/html; charset=utf-8"
return c.RenderTemplate("Step/Step.html")
}
示例10: Step
func (c App) Step() revel.Result {
sessionId := global.GetSessionId()
defer global.CloseSession(sessionId)
userId, err := strconv.Atoi(c.Session["userId"])
if err != nil {
panic(err)
}
sysUser := map[string]interface{}{}
_, db := global.GetConnection(sessionId)
err = db.C("SysUser").Find(map[string]interface{}{
"id": userId,
}).One(&sysUser)
sysUserMain := sysUser["A"].(map[string]interface{})
maxStep := map[string]interface{}{}
err = db.C("SysStep").Find(map[string]interface{}{
"A.sysUnitId": sysUserMain["createUnit"],
}).Sort("-A.type").Limit(1).One(&maxStep)
if err != nil {
panic(err)
}
currentStep := map[string]interface{}{}
err = db.C("SysStep").Find(map[string]interface{}{
"A.sysUnitId": sysUserMain["createUnit"],
"A.status": 1,
}).Sort("A.type").Limit(1).One(¤tStep)
currentId := 0
maxStepMain := maxStep["A"].(map[string]interface{})
if err != nil {
currentId = CommonUtil{}.GetIntFromMap(maxStepMain, "type") + 1
} else {
currentStepMain := currentStep["A"].(map[string]interface{})
currentId = CommonUtil{}.GetIntFromMap(currentStepMain, "type")
}
response := map[string]interface{}{
"maxId": maxStepMain["type"],
"currentId": currentId,
}
return c.RenderJson(response)
}
示例11: BbsPostAdminReplySchema
// 管理員查看頁麵,設置session.userId,以查看數據,
func (c Console) BbsPostAdminReplySchema() revel.Result {
// 取一下bbsPostId
sessionId := global.GetSessionId()
global.SetGlobalAttr(sessionId, "userId", c.Session["userId"])
global.SetGlobalAttr(sessionId, "adminUserId", c.Session["adminUserId"])
defer global.CloseSession(sessionId)
defer c.RRollbackTxn(sessionId)
schemaName := c.Params.Get("@name")
templateManager := TemplateManager{}
listTemplate := templateManager.GetListTemplate(schemaName)
isFromList := true
result := c.listSelectorCommon(&listTemplate, true, isFromList)
bbsPostIdStr := c.Params.Get("bbsPostId")
bbsPostId, err := strconv.Atoi(bbsPostIdStr)
if err != nil {
panic(err)
}
c.addOrUpdateBbsPostRead(sessionId, bbsPostId)
c.CommitTxn(sessionId)
format := c.Params.Get("format")
if strings.ToLower(format) == "json" {
callback := c.Params.Get("callback")
if callback == "" {
dataBo := result["dataBo"]
c.Response.ContentType = "application/json; charset=utf-8"
return c.RenderJson(&dataBo)
}
dataBoText := result["dataBoText"].(string)
c.Response.ContentType = "text/javascript; charset=utf-8"
return c.RenderText(callback + "(" + dataBoText + ");")
} else {
//c.Response.ContentType = "text/html; charset=utf-8"
c.RenderArgs["result"] = result
return c.RenderTemplate(listTemplate.ViewTemplate.View)
// return c.Render(result)
}
}
示例12: RNewDataCommon
func (c BaseDataAction) RNewDataCommon() ModelRenderVO {
sessionId := global.GetSessionId()
global.SetGlobalAttr(sessionId, "userId", c.Session["userId"])
global.SetGlobalAttr(sessionId, "adminUserId", c.Session["adminUserId"])
defer global.CloseSession(sessionId)
defer c.RRollbackTxn(sessionId)
userId, err := strconv.Atoi(c.Session["userId"])
if err != nil {
panic(err)
}
dataSourceModelId := c.Params.Get("dataSourceModelId")
formTemplateId := c.Params.Get("formTemplateId")
modelTemplateFactory := ModelTemplateFactory{}
dataSource := modelTemplateFactory.GetDataSource(dataSourceModelId)
templateManager := TemplateManager{}
formTemplate := templateManager.GetFormTemplate(formTemplateId)
c.RActionSupport.RBeforeNewData(sessionId, dataSource, formTemplate)
bo := modelTemplateFactory.GetInstanceByDS(dataSource)
c.RActionSupport.RAfterNewData(sessionId, dataSource, formTemplate, &bo)
columnModelData := templateManager.GetColumnModelDataForFormTemplate(sessionId, formTemplate, bo)
bo = columnModelData["bo"].(map[string]interface{})
relationBo := columnModelData["relationBo"].(map[string]interface{})
modelTemplateFactory.ClearReverseRelation(&dataSource)
c.CommitTxn(sessionId)
return ModelRenderVO{
UserId: userId,
Bo: bo,
RelationBo: relationBo,
DataSource: dataSource,
FormTemplate: formTemplate,
}
}
示例13: Run
func (o StepService) Run(sysUser map[string]interface{}) {
sysUserManster := sysUser["A"].(map[string]interface{})
sysUnitId := CommonUtil{}.GetIntFromMap(sysUserManster, "createUnit")
// 加鎖
lockService := LockService{}
unitLock := lockService.GetUnitLock(fmt.Sprint(sysUnitId))
(*unitLock).Lock()
defer (*unitLock).Unlock()
sessionId := global.GetSessionId()
defer global.CloseSession(sessionId)
defer global.RollbackTxn(sessionId)
txnId := global.GetTxnId(sessionId)
_, db := global.GetConnection(sessionId)
txnManager := TxnManager{db}
stepLi := []map[string]interface{}{}
err := db.C("SysStep").Find(map[string]interface{}{
"A.sysUnitId": sysUnitId,
}).Sort("A.type").All(&stepLi)
if err != nil {
panic(err)
}
for _, item := range stepLi {
master := item["A"].(map[string]interface{})
item["A"] = master
status := fmt.Sprint(master["status"])
if status == "1" { // 未開始
stepType := fmt.Sprint(master["type"])
if stepType == "3" { //初始化供應商類別
o.InitProviderType(sessionId, sysUser)
} else if stepType == "5" { //初始化幣別
o.InitCurrencyType(sessionId, sysUser)
} else if stepType == "6" { //初始化銀行資料
o.InitBank(sessionId, sysUser)
} else if stepType == "7" { //初始化計量單位
o.InitMeasureUnit(sessionId, sysUser)
} else if stepType == "9" { //初始化客戶類別
o.InitCustomerType(sessionId, sysUser)
} else if stepType == "12" { //初始化稅率類別
o.InitTaxType(sessionId, sysUser)
} else if stepType == "14" { //初始化收入費用類別
o.InitIncomeType(sessionId, sysUser)
} else if stepType == "15" { //初始化收入費用項目
o.InitIncomeItem(sessionId, sysUser)
} else if stepType == "16" { //初始化會計期
o.InitAccountingPeriod(sessionId, sysUser)
} else if stepType == "18" { //初始化收款單類型參數
o.InitBillReceiveTypeParameter(sessionId, sysUser)
} else if stepType == "19" { //初始化付款單類型參數
o.InitBillPaymentTypeParameter(sessionId, sysUser)
} else if stepType == "20" { //初始化係統參數
o.InitSystemParameter(sessionId, sysUser)
}
}
master["status"] = 2
_, updateResult := txnManager.Update(txnId, "SysStep", item)
if !updateResult {
panic(BusinessError{Message: "更新SysStep" + fmt.Sprint(master["name"]) + "失敗"})
}
}
global.CommitTxn(sessionId)
}
示例14: RGetDataCommon
func (c AccountInOutDisplay) RGetDataCommon() ModelRenderVO {
sessionId := global.GetSessionId()
global.SetGlobalAttr(sessionId, "userId", c.Session["userId"])
global.SetGlobalAttr(sessionId, "adminUserId", c.Session["adminUserId"])
defer global.CloseSession(sessionId)
defer c.RRollbackTxn(sessionId)
userId, err := strconv.Atoi(c.Session["userId"])
if err != nil {
panic(err)
}
dataSourceModelId := c.Params.Get("dataSourceModelId")
formTemplateId := c.Params.Get("formTemplateId")
jsonData := c.Params.Get("jsonData")
jsonMap := map[string]interface{}{}
err = json.Unmarshal([]byte(jsonData), &jsonMap)
if err != nil {
panic(err)
}
queryMap := jsonMap["A"].(map[string]interface{})
modelTemplateFactory := ModelTemplateFactory{}
dataSource := modelTemplateFactory.GetDataSource(dataSourceModelId)
templateManager := TemplateManager{}
formTemplate := templateManager.GetFormTemplate(formTemplateId)
accountLi := c.getAccountList(sessionId, formTemplate, queryMap)
origBalanceLi := c.getOrigBalanceList(sessionId, formTemplate, queryMap)
increaseReduceBalanceLi := c.getIncreaseReduceBalanceList(sessionId, formTemplate, queryMap)
dataSetLi := c.mergeAndCalceFinalBalance(accountLi, origBalanceLi, increaseReduceBalanceLi)
dataSetLi = c.filterEmpty(dataSetLi, queryMap)
bo := map[string]interface{}{
"_id": 0,
"id": 0,
"A": map[string]interface{}{
"id": 0,
},
"B": dataSetLi,
}
// usedCheck := UsedCheck{}
// usedCheckBo := usedCheck.GetFormUsedCheck(sessionId, dataSource, bo)
usedCheckBo := map[string]interface{}{}
columnModelData := templateManager.GetColumnModelDataForFormTemplate(sessionId, formTemplate, bo)
bo = columnModelData["bo"].(map[string]interface{})
relationBo := columnModelData["relationBo"].(map[string]interface{})
modelTemplateFactory.ConvertDataType(dataSource, &bo)
modelTemplateFactory.ClearReverseRelation(&dataSource)
return ModelRenderVO{
UserId: userId,
Bo: bo,
RelationBo: relationBo,
UsedCheckBo: usedCheckBo,
DataSource: dataSource,
}
}
示例15: Summary
func (c Console) Summary() revel.Result {
println("session is:", c.Session["userId"])
sessionId := global.GetSessionId()
global.SetGlobalAttr(sessionId, "userId", c.Session["userId"])
global.SetGlobalAttr(sessionId, "adminUserId", c.Session["adminUserId"])
defer global.CloseSession(sessionId)
templateManager := TemplateManager{}
formTemplate := templateManager.GetFormTemplate("Console")
// if true {
// xmlDataArray, err := xml.Marshal(&formTemplate)
// if err != nil {
// panic(err)
// }
// return c.RenderXml(&formTemplate)
// }
formTemplateJsonDataArray, err := json.Marshal(&formTemplate)
if err != nil {
panic(err)
}
toolbarBo := map[string]interface{}{}
dataBo := map[string]interface{}{}
{
listTemplateInfoLi := templateManager.GetListTemplateInfoLi()
dataBo["Component"] = getSummaryListTemplateInfoLi(listTemplateInfoLi)
}
{
selectorTemplateInfoLi := templateManager.GetSelectorTemplateInfoLi()
dataBo["Selector"] = getSummarySelectorTemplateInfoLi(selectorTemplateInfoLi)
}
{
formTemplateInfoLi := templateManager.GetFormTemplateInfoLi()
dataBo["Form"] = getSummaryFormTemplateInfoLi(formTemplateInfoLi)
}
{
modelTemplateFactory := ModelTemplateFactory{}
dataSourceInfoLi := modelTemplateFactory.GetDataSourceInfoLi()
dataBo["DataSource"] = getSummaryDataSourceInfoLi(dataSourceInfoLi)
}
for _, item := range formTemplate.FormElemLi {
if item.XMLName.Local == "column-model" {
if dataBo[item.ColumnModel.Name] == nil {
dataBo[item.ColumnModel.Name] = []interface{}{}
}
items := dataBo[item.ColumnModel.Name].([]interface{})
itemsDict := templateManager.GetColumnModelDataForColumnModel(sessionId, item.ColumnModel, items)
items = itemsDict["items"].([]interface{})
dataBo[item.ColumnModel.Name] = items
} else if item.XMLName.Local == "toolbar" {
toolbarBo[item.Toolbar.Name] = templateManager.GetToolbarBo(item.Toolbar)
}
}
dataBoByte, err := json.Marshal(dataBo)
if err != nil {
panic(err)
}
// c.Response.Status = http.StatusOK
// c.Response.ContentType = "text/plain; charset=utf-8"
result := map[string]interface{}{
"formTemplate": formTemplate,
"toolbarBo": toolbarBo,
"dataBo": dataBo,
"formTemplateJsonData": template.JS(string(formTemplateJsonDataArray)),
"dataBoJson": template.JS(string(dataBoByte)),
}
// formTemplate.ViewTemplate.View
// RenderText(text string, objs ...interface{}) Result
viewPath := revel.Config.StringDefault("REVEL_VIEW_PATH", "")
file, err := os.Open(viewPath + "/" + formTemplate.ViewTemplate.View)
defer file.Close()
if err != nil {
panic(err)
}
fileContent, err := ioutil.ReadAll(file)
if err != nil {
panic(err)
}
// c.Response.Out
// return c.RenderTemplate(string(fileContent))
funcMap := map[string]interface{}{
"eq": func(a, b interface{}) bool {
return a == b
},
}
//c.Response.ContentType = "text/html; charset=utf-8"
tmpl, err := template.New("summary").Funcs(funcMap).Parse(string(fileContent))
if err != nil {
panic(err)
}
tmplResult := map[string]interface{}{
"result": result,
}
//.........這裏部分代碼省略.........