From ae0b10f0459af5bc7b1fbac762e81fff58b4bfac Mon Sep 17 00:00:00 2001 From: Patrick Lindsay Date: Wed, 25 Sep 2024 12:47:26 -0500 Subject: [PATCH] Convert SourceType to string type --- fastly/observability_custom_dashboard.go | 44 +++--------------------- 1 file changed, 4 insertions(+), 40 deletions(-) diff --git a/fastly/observability_custom_dashboard.go b/fastly/observability_custom_dashboard.go index ba9a3899f..881e56cfa 100644 --- a/fastly/observability_custom_dashboard.go +++ b/fastly/observability_custom_dashboard.go @@ -2,8 +2,6 @@ package fastly import ( "encoding/json" - "errors" - "fmt" "net/http" "strconv" "time" @@ -55,48 +53,14 @@ type DashboardItem struct { Visualization Visualization `json:"visualization"` } -type SourceType int +type SourceType string const ( - SourceTypeUndefined SourceType = iota - SourceTypeStatsEdge - SourceTypeStatsDomain - SourceTypeStatsOrigin + SourceTypeStatsEdge = "stats.edge" + SourceTypeStatsDomain = "stats.domain" + SourceTypeStatsOrigin = "stats.origin" ) -var stringToSourceType = map[string]SourceType{ - "stats.edge": SourceTypeStatsEdge, - "stats.domain": SourceTypeStatsDomain, - "stats.origin": SourceTypeStatsOrigin, -} - -var sourceTypeToString = map[SourceType]string{ - SourceTypeStatsEdge: "stats.edge", - SourceTypeStatsDomain: "stats.domain", - SourceTypeStatsOrigin: "stats.origin", -} - -func (st SourceType) String() string { - return sourceTypeToString[st] -} -func (st SourceType) MarshalJSON() ([]byte, error) { - if st == SourceTypeUndefined { - return nil, errors.New("cannot marshal undefined SourceType") - } - return json.Marshal(st.String()) -} -func (st *SourceType) UnmarshalJSON(data []byte) (err error) { - var str string - if err = json.Unmarshal(data, &str); err != nil { - return err - } - var ok bool - if *st, ok = stringToSourceType[str]; !ok { - return NewFieldError("DataSource.Type").Message(fmt.Sprintf("Invalid value \"%s\" for DataSource.Type", data)) - } - return nil -} - type DataSource struct { // Config describes configuration options for the selected data source (required). Config SourceConfig `json:"config"`