Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ratelimiter): use separate structs for input/response serialization #418

Merged
merged 1 commit into from
Mar 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 27 additions & 20 deletions fastly/erl.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,40 @@ import (

// ERL models the response from the Fastly API.
type ERL struct {
Action ERLAction `mapstructure:"action"`
ClientKey []string `mapstructure:"client_key"`
CreatedAt *time.Time `mapstructure:"created_at"`
DeletedAt *time.Time `mapstructure:"deleted_at"`
FeatureRevision int `mapstructure:"feature_revision"` // 1..
HTTPMethods []string `mapstructure:"http_methods"`
ID string `mapstructure:"id"`
LoggerType ERLLogger `mapstructure:"logger_type"`
Name string `mapstructure:"name"`
PenaltyBoxDuration int `mapstructure:"penalty_box_duration"` // 1..60
Response *ERLResponseType `mapstructure:"response"` // required if Action != Log
ResponseObjectName string `mapstructure:"response_object_name"`
RpsLimit int `mapstructure:"rps_limit"` // 10..10000
ServiceID string `mapstructure:"service_id"`
UpdatedAt *time.Time `mapstructure:"updated_at"`
URIDictionaryName string `mapstructure:"uri_dictionary_name"`
Version int `mapstructure:"version"` // 1..
WindowSize ERLWindowSize `mapstructure:"window_size"`
Action ERLAction `mapstructure:"action"`
ClientKey []string `mapstructure:"client_key"`
CreatedAt *time.Time `mapstructure:"created_at"`
DeletedAt *time.Time `mapstructure:"deleted_at"`
FeatureRevision int `mapstructure:"feature_revision"` // 1..
HTTPMethods []string `mapstructure:"http_methods"`
ID string `mapstructure:"id"`
LoggerType ERLLogger `mapstructure:"logger_type"`
Name string `mapstructure:"name"`
PenaltyBoxDuration int `mapstructure:"penalty_box_duration"` // 1..60
Response *ERLResponse `mapstructure:"response"` // required if Action != Log
ResponseObjectName string `mapstructure:"response_object_name"`
RpsLimit int `mapstructure:"rps_limit"` // 10..10000
ServiceID string `mapstructure:"service_id"`
UpdatedAt *time.Time `mapstructure:"updated_at"`
URIDictionaryName string `mapstructure:"uri_dictionary_name"`
Version int `mapstructure:"version"` // 1..
WindowSize ERLWindowSize `mapstructure:"window_size"`
}

// ERLResponseType models the response from the Fastly API.
type ERLResponseType struct {
// ERLResponse models the response from the Fastly API.
type ERLResponse struct {
ERLContent string `mapstructure:"content,omitempty"`
ERLContentType string `mapstructure:"content_type,omitempty"`
ERLStatus int `mapstructure:"status,omitempty"`
}

// ERLResponseType models the input to the Fastly API.
type ERLResponseType struct {
ERLContent string `url:"content,omitempty"`
ERLContentType string `url:"content_type,omitempty"`
ERLStatus int `url:"status,omitempty"`
}

// ERLAction represents the action variants for when a rate limiter
// violation is detected.
type ERLAction string
Expand Down