1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- package rest
- import (
- "io"
- "net/http"
- "git.ali33.ru/fcg-xvii/go-tools/json"
- )
- type Request struct {
- *http.Request
- auth json.Map
- data json.Map
- files map[string]io.ReadCloser
- tokenGenerator func(json.Map, int64) (string, error)
- }
- func (s *Request) GenerateToken(data json.Map, expire int64) (string, error) {
- return s.tokenGenerator(data, expire)
- }
- func (s *Request) RPath() string {
- return s.URL.Path
- }
- func (s *Request) Data() json.Map {
- return s.data
- }
- // file keys
- func (s *Request) FileKeys() []string {
- res := make([]string, 0, len(s.files))
- for k := range s.files {
- res = append(res, k)
- }
- return res
- }
- func (s *Request) File(name string) (io.Reader, bool) {
- r, check := s.files[name]
- return r, check
- }
- // Auth returns auth data
- func (s *Request) Auth() json.Map {
- return s.auth
- }
- func (s *Request) IsAuth() bool {
- return s.auth != nil
- }
- func (s *Request) IsJSON() bool {
- return s.Header.Get("Content-Type") == "application/json"
- }
- func (s *Request) IsForm() bool {
- return s.Header.Get("Content-Type") == "application/x-www-form-urlencoded"
- }
- func (s *Request) Close() {
- for _, file := range s.files {
- file.Close()
- }
- }
|