Skip to content

Commit

Permalink
chore: Fix linter findings for revive:max-public-structs in plugins/i…
Browse files Browse the repository at this point in the history
…nputs/[t-z]* and rest
  • Loading branch information
zak-pawel committed Sep 13, 2024
1 parent ffee74c commit 9655d18
Show file tree
Hide file tree
Showing 30 changed files with 535 additions and 540 deletions.
28 changes: 14 additions & 14 deletions plugins/inputs/tomcat/tomcat.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,23 @@ import (
//go:embed sample.conf
var sampleConfig string

type TomcatStatus struct {
TomcatJvm TomcatJvm `xml:"jvm"`
TomcatConnectors []TomcatConnector `xml:"connector"`
type tomcatStatus struct {
TomcatJvm tomcatJvm `xml:"jvm"`
TomcatConnectors []tomcatConnector `xml:"connector"`
}

type TomcatJvm struct {
JvmMemory JvmMemoryStat `xml:"memory"`
JvmMemoryPools []JvmMemoryPoolStat `xml:"memorypool"`
type tomcatJvm struct {
JvmMemory jvmMemoryStat `xml:"memory"`
JvmMemoryPools []jvmMemoryPoolStat `xml:"memorypool"`
}

type JvmMemoryStat struct {
type jvmMemoryStat struct {
Free int64 `xml:"free,attr"`
Total int64 `xml:"total,attr"`
Max int64 `xml:"max,attr"`
}

type JvmMemoryPoolStat struct {
type jvmMemoryPoolStat struct {
Name string `xml:"name,attr"`
Type string `xml:"type,attr"`
UsageInit int64 `xml:"usageInit,attr"`
Expand All @@ -44,18 +44,18 @@ type JvmMemoryPoolStat struct {
UsageUsed int64 `xml:"usageUsed,attr"`
}

type TomcatConnector struct {
type tomcatConnector struct {
Name string `xml:"name,attr"`
ThreadInfo ThreadInfo `xml:"threadInfo"`
RequestInfo RequestInfo `xml:"requestInfo"`
ThreadInfo threadInfo `xml:"threadInfo"`
RequestInfo requestInfo `xml:"requestInfo"`
}

type ThreadInfo struct {
type threadInfo struct {
MaxThreads int64 `xml:"maxThreads,attr"`
CurrentThreadCount int64 `xml:"currentThreadCount,attr"`
CurrentThreadsBusy int64 `xml:"currentThreadsBusy,attr"`
}
type RequestInfo struct {
type requestInfo struct {
MaxTime int `xml:"maxTime,attr"`
ProcessingTime int `xml:"processingTime,attr"`
RequestCount int `xml:"requestCount,attr"`
Expand Down Expand Up @@ -112,7 +112,7 @@ func (s *Tomcat) Gather(acc telegraf.Accumulator) error {
resp.StatusCode, s.URL)
}

var status TomcatStatus
var status tomcatStatus
if err := xml.NewDecoder(resp.Body).Decode(&status); err != nil {
return err
}
Expand Down
20 changes: 10 additions & 10 deletions plugins/inputs/webhooks/artifactory/artifactory_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,35 +70,35 @@ func (e *newEventError) Error() string {
return e.s
}

func (awh *ArtifactoryWebhook) NewEvent(data []byte, et, ed string) (Event, error) {
func (awh *ArtifactoryWebhook) NewEvent(data []byte, et, ed string) (event, error) {
awh.log.Debugf("New %v domain %v event received", ed, et)
switch ed {
case "artifact":
if et == "deployed" || et == "deleted" {
return generateEvent(data, &ArtifactDeploymentOrDeletedEvent{})
return generateEvent(data, &artifactDeploymentOrDeletedEvent{})
} else if et == "moved" || et == "copied" {
return generateEvent(data, &ArtifactMovedOrCopiedEvent{})
return generateEvent(data, &artifactMovedOrCopiedEvent{})
} else {
return nil, &newEventError{"Not a recognized event type"}
}
case "artifact_property":
return generateEvent(data, &ArtifactPropertiesEvent{})
return generateEvent(data, &artifactPropertiesEvent{})
case "docker":
return generateEvent(data, &DockerEvent{})
return generateEvent(data, &dockerEvent{})
case "build":
return generateEvent(data, &BuildEvent{})
return generateEvent(data, &buildEvent{})
case "release_bundle":
return generateEvent(data, &ReleaseBundleEvent{})
return generateEvent(data, &releaseBundleEvent{})
case "distribution":
return generateEvent(data, &DistributionEvent{})
return generateEvent(data, &distributionEvent{})
case "destination":
return generateEvent(data, &DestinationEvent{})
return generateEvent(data, &destinationEvent{})
}

return nil, &newEventError{"Not a recognized event type"}
}

func generateEvent(data []byte, event Event) (Event, error) {
func generateEvent(data []byte, event event) (event, error) {
err := json.Unmarshal(data, event)
if err != nil {
return nil, err
Expand Down
39 changes: 17 additions & 22 deletions plugins/inputs/webhooks/artifactory/artifactory_webhook_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,11 @@ import (

const meas = "artifactory_webhooks"

type CommonFields struct {
Domain string `json:"domain"`
Event string `json:"event_type"`
}

type Event interface {
type event interface {
NewMetric() telegraf.Metric
}

type ArtifactDeploymentOrDeletedEvent struct {
type artifactDeploymentOrDeletedEvent struct {
Domain string `json:"domain"`
Event string `json:"event_type"`
Data struct {
Expand All @@ -31,7 +26,7 @@ type ArtifactDeploymentOrDeletedEvent struct {
} `json:"data"`
}

func (e ArtifactDeploymentOrDeletedEvent) NewMetric() telegraf.Metric {
func (e artifactDeploymentOrDeletedEvent) NewMetric() telegraf.Metric {
t := map[string]string{
"domain": e.Domain,
"event_type": e.Event,
Expand All @@ -47,7 +42,7 @@ func (e ArtifactDeploymentOrDeletedEvent) NewMetric() telegraf.Metric {
return metric.New(meas, t, f, time.Now())
}

type ArtifactMovedOrCopiedEvent struct {
type artifactMovedOrCopiedEvent struct {
Domain string `json:"domain"`
Event string `json:"event_type"`
Data struct {
Expand All @@ -60,7 +55,7 @@ type ArtifactMovedOrCopiedEvent struct {
} `json:"data"`
}

func (e ArtifactMovedOrCopiedEvent) NewMetric() telegraf.Metric {
func (e artifactMovedOrCopiedEvent) NewMetric() telegraf.Metric {
t := map[string]string{
"domain": e.Domain,
"event_type": e.Event,
Expand All @@ -77,7 +72,7 @@ func (e ArtifactMovedOrCopiedEvent) NewMetric() telegraf.Metric {
return metric.New(meas, t, f, time.Now())
}

type ArtifactPropertiesEvent struct {
type artifactPropertiesEvent struct {
Domain string `json:"domain"`
Event string `json:"event_type"`
Data struct {
Expand All @@ -90,7 +85,7 @@ type ArtifactPropertiesEvent struct {
}
}

func (e ArtifactPropertiesEvent) NewMetric() telegraf.Metric {
func (e artifactPropertiesEvent) NewMetric() telegraf.Metric {
t := map[string]string{
"domain": e.Domain,
"event_type": e.Event,
Expand All @@ -107,7 +102,7 @@ func (e ArtifactPropertiesEvent) NewMetric() telegraf.Metric {
return metric.New(meas, t, f, time.Now())
}

type DockerEvent struct {
type dockerEvent struct {
Domain string `json:"domain"`
Event string `json:"event_type"`
Data struct {
Expand All @@ -125,7 +120,7 @@ type DockerEvent struct {
} `json:"data"`
}

func (e DockerEvent) NewMetric() telegraf.Metric {
func (e dockerEvent) NewMetric() telegraf.Metric {
t := map[string]string{
"domain": e.Domain,
"event_type": e.Event,
Expand All @@ -144,7 +139,7 @@ func (e DockerEvent) NewMetric() telegraf.Metric {
return metric.New(meas, t, f, time.Now())
}

type BuildEvent struct {
type buildEvent struct {
Domain string `json:"domain"`
Event string `json:"event_type"`
Data struct {
Expand All @@ -154,7 +149,7 @@ type BuildEvent struct {
} `json:"data"`
}

func (e BuildEvent) NewMetric() telegraf.Metric {
func (e buildEvent) NewMetric() telegraf.Metric {
t := map[string]string{
"domain": e.Domain,
"event_type": e.Event,
Expand All @@ -168,7 +163,7 @@ func (e BuildEvent) NewMetric() telegraf.Metric {
return metric.New(meas, t, f, time.Now())
}

type ReleaseBundleEvent struct {
type releaseBundleEvent struct {
Domain string `json:"domain"`
Event string `json:"event_type"`
Destination string `json:"destination"`
Expand All @@ -180,7 +175,7 @@ type ReleaseBundleEvent struct {
JpdOrigin string `json:"jpd_origin"`
}

func (e ReleaseBundleEvent) NewMetric() telegraf.Metric {
func (e releaseBundleEvent) NewMetric() telegraf.Metric {
t := map[string]string{
"domain": e.Domain,
"event_type": e.Event,
Expand All @@ -196,7 +191,7 @@ func (e ReleaseBundleEvent) NewMetric() telegraf.Metric {
return metric.New(meas, t, f, time.Now())
}

type DistributionEvent struct {
type distributionEvent struct {
Domain string `json:"domain"`
Event string `json:"event_type"`
Destination string `json:"destination"`
Expand All @@ -214,7 +209,7 @@ type DistributionEvent struct {
OriginURL string `json:"jpd_origin"`
}

func (e DistributionEvent) NewMetric() telegraf.Metric {
func (e distributionEvent) NewMetric() telegraf.Metric {
t := map[string]string{
"domain": e.Domain,
"event_type": e.Event,
Expand All @@ -232,7 +227,7 @@ func (e DistributionEvent) NewMetric() telegraf.Metric {
return metric.New(meas, t, f, time.Now())
}

type DestinationEvent struct {
type destinationEvent struct {
Domain string `json:"domain"`
Event string `json:"event_type"`
Destination string `json:"destination"`
Expand All @@ -244,7 +239,7 @@ type DestinationEvent struct {
OriginURL string `json:"jpd_origin"`
}

func (e DestinationEvent) NewMetric() telegraf.Metric {
func (e destinationEvent) NewMetric() telegraf.Metric {
t := map[string]string{
"domain": e.Domain,
"event_type": e.Event,
Expand Down
46 changes: 23 additions & 23 deletions plugins/inputs/webhooks/github/github_webhooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (gh *GithubWebhook) eventHandler(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
}

func generateEvent(data []byte, event Event) (Event, error) {
func generateEvent(data []byte, event event) (event, error) {
err := json.Unmarshal(data, event)
if err != nil {
return nil, err
Expand All @@ -80,53 +80,53 @@ func (e *newEventError) Error() string {
return e.s
}

func (gh *GithubWebhook) NewEvent(data []byte, name string) (Event, error) {
func (gh *GithubWebhook) NewEvent(data []byte, name string) (event, error) {
gh.log.Debugf("New %v event received", name)
switch name {
case "commit_comment":
return generateEvent(data, &CommitCommentEvent{})
return generateEvent(data, &commitCommentEvent{})
case "create":
return generateEvent(data, &CreateEvent{})
return generateEvent(data, &createEvent{})
case "delete":
return generateEvent(data, &DeleteEvent{})
return generateEvent(data, &deleteEvent{})
case "deployment":
return generateEvent(data, &DeploymentEvent{})
return generateEvent(data, &deploymentEvent{})
case "deployment_status":
return generateEvent(data, &DeploymentStatusEvent{})
return generateEvent(data, &deploymentStatusEvent{})
case "fork":
return generateEvent(data, &ForkEvent{})
return generateEvent(data, &forkEvent{})
case "gollum":
return generateEvent(data, &GollumEvent{})
return generateEvent(data, &gollumEvent{})
case "issue_comment":
return generateEvent(data, &IssueCommentEvent{})
return generateEvent(data, &issueCommentEvent{})
case "issues":
return generateEvent(data, &IssuesEvent{})
return generateEvent(data, &issuesEvent{})
case "member":
return generateEvent(data, &MemberEvent{})
return generateEvent(data, &memberEvent{})
case "membership":
return generateEvent(data, &MembershipEvent{})
return generateEvent(data, &membershipEvent{})
case "page_build":
return generateEvent(data, &PageBuildEvent{})
return generateEvent(data, &pageBuildEvent{})
case "ping":
return nil, nil
case "public":
return generateEvent(data, &PublicEvent{})
return generateEvent(data, &publicEvent{})
case "pull_request":
return generateEvent(data, &PullRequestEvent{})
return generateEvent(data, &pullRequestEvent{})
case "pull_request_review_comment":
return generateEvent(data, &PullRequestReviewCommentEvent{})
return generateEvent(data, &pullRequestReviewCommentEvent{})
case "push":
return generateEvent(data, &PushEvent{})
return generateEvent(data, &pushEvent{})
case "release":
return generateEvent(data, &ReleaseEvent{})
return generateEvent(data, &releaseEvent{})
case "repository":
return generateEvent(data, &RepositoryEvent{})
return generateEvent(data, &repositoryEvent{})
case "status":
return generateEvent(data, &StatusEvent{})
return generateEvent(data, &statusEvent{})
case "team_add":
return generateEvent(data, &TeamAddEvent{})
return generateEvent(data, &teamAddEvent{})
case "watch":
return generateEvent(data, &WatchEvent{})
return generateEvent(data, &watchEvent{})
}
return nil, &newEventError{"Not a recognized event type"}
}
Expand Down
Loading

0 comments on commit 9655d18

Please sign in to comment.