-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SetValue can handle all primitive types, except complex and uintptr.
Add tests for each case.
- Loading branch information
1 parent
ebf6364
commit 0457671
Showing
14 changed files
with
1,436 additions
and
241 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,5 @@ _testmain.go | |
*.exe | ||
*.test | ||
*.prof | ||
|
||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
include: | ||
- project: "infrastructure/templates" | ||
ref: master | ||
file: "/.golang.yml" | ||
- project: "infrastructure/templates" | ||
ref: master | ||
file: "/.runner-tags.yml" | ||
|
||
image: ${INFRA_GOLANG_IMAGE} | ||
|
||
stages: | ||
- test | ||
|
||
golangci-lint: | ||
stage: test | ||
before_script: | ||
- export GO111MODULE=on | ||
- go mod download | ||
script: | ||
- go version | ||
- golangci-lint run ./... | ||
extends: .INFRA_RUNNER_TAGS_K8S | ||
|
||
testing: | ||
stage: test | ||
coverage: '/^total:\t+\(statements\)\t+(\d+\.\d+)%/' | ||
before_script: | ||
- export GO111MODULE=on | ||
- go mod download | ||
script: | ||
- go version | ||
- go test ./... -coverprofile cover.out | ||
- go tool cover -func cover.out | ||
extends: .INFRA_RUNNER_TAGS_K8S | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
run: | ||
deadline: 5m | ||
tests: false | ||
|
||
linters-settings: | ||
errcheck: | ||
# ignore stupid FlagCheck that is already checked, rest is default | ||
ignore: fmt:.* | ||
|
||
linters: | ||
enable-all: true | ||
fast: false | ||
|
||
issues: | ||
max-issues-per-linter: 50 | ||
max-same-issues: 50 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
language: go | ||
|
||
env: | ||
- GO111MODULE=on | ||
|
||
git: | ||
depth: 1 | ||
|
||
go: | ||
- 1.12.x | ||
- 1.13.x | ||
|
||
before_script: | ||
- go install github.com/golangci/golangci-lint/cmd/golangci-lint | ||
|
||
script: | ||
- golangci-lint run ./... | ||
- go test ./... -coverprofile cover.out | ||
- go tool cover -func cover.out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
Copyright (c) 2016, Paessler AG <[email protected]> | ||
Copyright (c) 2019, Paessler AG <[email protected]> | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module github.com/PRTG/go-prtg-sensor-api | ||
|
||
go 1.13 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright (c) 2019, Paessler AG. | ||
// All Rights Reserved | ||
|
||
// Package PRTG implements the API for PRTG custom sensors. | ||
// It provides all structs and constants needed to implement your own advanced exe sensor in Go. | ||
package prtg | ||
|
||
import ( | ||
"encoding/json" | ||
) | ||
|
||
// SensorStatus has the whole JSON object | ||
type SensorResponse struct { | ||
SensorResults SensorResults `json:"prtg"` | ||
} | ||
|
||
// SensorResults has all the channels | ||
type SensorResults struct { | ||
SensorChannels []SensorChannel `json:"result"` | ||
Text string `json:"text,omitempty"` | ||
Error string `json:"error,omitempty"` | ||
} | ||
|
||
type Sensor interface { | ||
AddChannel(string) *SensorChannel | ||
MarshalToString() (string, error) | ||
SetSensorText(string) *SensorResults | ||
SetError(bool) *SensorResults | ||
} | ||
|
||
// Creates the Sensor instance and returns the interface. | ||
func New() Sensor { | ||
return &SensorResults{} | ||
} | ||
|
||
// Name of the channel as displayed in user interfaces. | ||
func (sr *SensorResults) AddChannel(channelName string) *SensorChannel { | ||
newChan := SensorChannel{Channel: channelName} | ||
sr.SensorChannels = append(sr.SensorChannels, newChan) | ||
|
||
return &sr.SensorChannels[len(sr.SensorChannels)-1] | ||
} | ||
|
||
// Create a JSON string from the PRTG object | ||
func (sr *SensorResults) MarshalToString() (string, error) { | ||
bytes, err := json.Marshal(&SensorResponse{*sr}) | ||
return string(bytes), err | ||
} | ||
|
||
// Text the sensor returns in the Message field with every scanning interval. | ||
// There can be one message per sensor, regardless of the number of channels. | ||
// Default is OK. | ||
func (sr *SensorResults) SetSensorText(text string) *SensorResults { | ||
sr.Text = text | ||
return sr | ||
} | ||
|
||
// If enabled, the sensor will return an error status. | ||
// This element can be combined with the SensorText element in order to show an error message. | ||
// Default is 0. | ||
func (sr *SensorResults) SetError(err bool) *SensorResults { | ||
sr.Error = "0" | ||
if err { | ||
sr.Error = "1" | ||
} | ||
|
||
return sr | ||
} |
Oops, something went wrong.