context.go 805 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package context
  2. import "net/http"
  3. //Context struct
  4. type Context struct {
  5. AppID string
  6. AppSecret string
  7. Token string
  8. EncodingAESKey string
  9. Writer http.ResponseWriter
  10. Request *http.Request
  11. }
  12. func (ctx *Context) getAccessToken() {
  13. }
  14. func (ctx *Context) String(str string) error {
  15. ctx.Writer.WriteHeader(200)
  16. _, err := ctx.Writer.Write([]byte(str))
  17. return err
  18. }
  19. // Query returns the keyed url query value if it exists
  20. func (ctx *Context) Query(key string) string {
  21. value, _ := ctx.GetQuery(key)
  22. return value
  23. }
  24. // GetQuery is like Query(), it returns the keyed url query value
  25. func (ctx *Context) GetQuery(key string) (string, bool) {
  26. req := ctx.Request
  27. if values, ok := req.URL.Query()[key]; ok && len(values) > 0 {
  28. return values[0], true
  29. }
  30. return "", false
  31. }