update comment for package gsession

This commit is contained in:
John
2020-03-22 00:15:59 +08:00
parent 17aea8d7d4
commit bfa64705b5
2 changed files with 36 additions and 54 deletions

View File

@ -1,54 +1,36 @@
package main
import (
"fmt"
"github.com/gogf/gf/encoding/gjson"
"github.com/gogf/gf/text/gstr"
"net/http"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/net/ghttp"
)
const (
TraceIdName = "trace-id"
)
func MiddlewareAuth(r *ghttp.Request) {
token := r.Get("token")
if token == "123456" {
r.Response.Writeln("auth")
r.Middleware.Next()
} else {
r.Response.WriteStatus(http.StatusForbidden)
}
}
func MiddlewareCORS(r *ghttp.Request) {
r.Response.Writeln("cors")
r.Response.CORSDefault()
r.Middleware.Next()
}
func main() {
type Sender struct {
Name string `json:"name"`
Email string `json:"email"`
}
type To struct {
Name string `json:"name"`
Email string `json:"email"`
}
type SendReq struct {
Sender *Sender `json:"sender"`
//Name string `json:"name"`
HtmlContent string `json:"htmlContent"`
Subject string `json:"subject"`
To []*To `json:"to"`
}
//url := "emailCampaigns"
sendreq := SendReq{
Sender: &Sender{
Name: "123",
Email: "globalclienthelp@gmail.com",
},
To: []*To{{
Name: "456",
//Email: order.Email,
Email: "jinmao88@hotmail.com",
}},
}
subject := ""
htmlcontent := ""
subject = " Your order" + gstr.Split("11111", "-")[1] + " Shipment is on its way."
htmlcontent = "test"
sendreq.Subject = subject
sendreq.HtmlContent = htmlcontent
j, err := gjson.DecodeToJson(sendreq)
fmt.Println(err)
fmt.Println(j)
s := g.Server()
s.Group("/api.v2", func(group *ghttp.RouterGroup) {
group.Middleware(MiddlewareCORS, MiddlewareAuth)
group.ALL("/user/list", func(r *ghttp.Request) {
r.Response.Writeln("list")
})
})
s.SetPort(8199)
s.Run()
}

View File

@ -16,22 +16,22 @@ type Storage interface {
// This function can be used for custom session creation.
New(ttl time.Duration) (id string)
// Get retrieves session value with given key.
// Get retrieves and returns session value with given key.
// It returns nil if the key does not exist in the session.
Get(id string, key string) interface{}
// GetMap retrieves all key-value pairs as map from storage.
GetMap(id string) map[string]interface{}
// GetSize retrieves the size of key-value pairs from storage.
// GetSize retrieves and returns the size of key-value pairs from storage.
GetSize(id string) int
// Set sets key-value session pair to the storage.
// The parameter <ttl> specifies the TTL for the session id (not for the key-value pair).
// Set sets one key-value session pair to the storage.
// The parameter <ttl> specifies the TTL for the session id.
Set(id string, key string, value interface{}, ttl time.Duration) error
// SetMap batch sets key-value session pairs with map to the storage.
// The parameter <ttl> specifies the TTL for the session id(not for the key-value pair).
// SetMap batch sets key-value session pairs as map to the storage.
// The parameter <ttl> specifies the TTL for the session id.
SetMap(id string, data map[string]interface{}, ttl time.Duration) error
// Remove deletes key with its value from storage.
@ -42,11 +42,11 @@ type Storage interface {
// GetSession returns the session data as *gmap.StrAnyMap for given session id from storage.
//
// The parameter <ttl> specifies the TTL for this session, and it returns nil if the TTL is exceeded.
// The parameter <ttl> specifies the TTL for this session.
// The parameter <data> is the current old session data stored in memory,
// and for some storage it might be nil if memory storage is disabled.
//
// This function is called ever when session starts.
// This function is called ever when session starts. It returns nil if the TTL is exceeded.
GetSession(id string, ttl time.Duration, data *gmap.StrAnyMap) (*gmap.StrAnyMap, error)
// SetSession updates the data for specified session id.