github.com/TeaOSLab/EdgeNode@v1.3.8/internal/waf/info_arg.go (about)

     1  // Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
     2  
     3  package waf
     4  
     5  import (
     6  	"github.com/TeaOSLab/EdgeNode/internal/utils"
     7  	"github.com/TeaOSLab/EdgeNode/internal/utils/fasttime"
     8  	"net/url"
     9  )
    10  
    11  type InfoArg struct {
    12  	ActionId         int64  `json:"1,omitempty"`
    13  	Timestamp        int64  `json:"2,omitempty"`
    14  	URL              string `json:"3,omitempty"`
    15  	PolicyId         int64  `json:"4,omitempty"`
    16  	GroupId          int64  `json:"5,omitempty"`
    17  	SetId            int64  `json:"6,omitempty"`
    18  	UseLocalFirewall bool   `json:"7,omitempty"`
    19  	Life             int32  `json:"8,omitempty"`
    20  	Scope            string `json:"9,omitempty"`
    21  	RemoteIP         string `json:"10,omitempty"`
    22  }
    23  
    24  func (this *InfoArg) IsValid() bool {
    25  	return this.Timestamp > 0
    26  }
    27  
    28  func (this *InfoArg) Encode() (string, error) {
    29  	if this.Timestamp <= 0 {
    30  		this.Timestamp = fasttime.Now().Unix()
    31  	}
    32  
    33  	return utils.SimpleEncryptObject(this)
    34  }
    35  
    36  func (this *InfoArg) URLEncoded() (string, error) {
    37  	encodedString, err := this.Encode()
    38  	if err != nil {
    39  		return "", err
    40  	}
    41  	return url.QueryEscape(encodedString), nil
    42  }
    43  
    44  func (this *InfoArg) Decode(encodedString string) error {
    45  	return utils.SimpleDecryptObjet(encodedString, this)
    46  }