Skip to content

Commit

Permalink
refactor(plugin): rename to service and cleanup interface
Browse files Browse the repository at this point in the history
  • Loading branch information
simskij committed Jun 9, 2019
1 parent bce84c9 commit 2e825c7
Show file tree
Hide file tree
Showing 52 changed files with 756 additions and 849 deletions.
15 changes: 8 additions & 7 deletions pkg/cli/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,16 @@ func Generate() Action {

serviceRouter := router.ServiceRouter{}

if service, err := serviceRouter.Locate(serviceSchema); err != nil {
service, err := serviceRouter.Locate(serviceSchema)
if err != nil {
fmt.Printf("invalid service schema '%s'\n", serviceSchema)
return 2
} else {
config := service.GetConfig()
configFormat := format.GetConfigMap(config) // TODO: GetConfigFormat
for key, format := range configFormat {
fmt.Printf("%s: %s", key, format)
}
}

config := service.GetConfig()
configFormat := format.GetConfigMap(config) // TODO: GetConfigFormat
for key, format := range configFormat {
fmt.Printf("%s: %s", key, format)
}

return 1
Expand Down
15 changes: 9 additions & 6 deletions pkg/cli/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"flag"
"fmt"
"github.com/containrrr/shoutrrr"
"github.com/containrrr/shoutrrr/pkg/plugin"
"github.com/containrrr/shoutrrr/pkg/services"
"log"
"os"
"strings"
Expand Down Expand Up @@ -36,15 +36,18 @@ func Send() Action {
fmt.Printf("Message: %s\n", message)


logger := plugin.DiscardLogger
var logger *log.Logger

if verbose {
logger = log.New(os.Stderr, "SHOUTRRR ", log.LstdFlags)
} else {
logger = services.DiscardLogger
}

opts := plugin.PluginOpts{
Verbose: verbose,
Logger: logger,
}
opts := services.CreateServiceOpts(
logger,
verbose,
map[string]string {})

shoutrrr.Send(url, message, opts)

Expand Down
39 changes: 39 additions & 0 deletions pkg/format/enum_formatter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package format

import (
"github.com/containrrr/shoutrrr/pkg/types"
"strings"
)

const EnumInvalid = -1

type EnumFormatter struct {
names []string
}

func (ef EnumFormatter) Names() []string {
return ef.names
}

func (ef EnumFormatter) Print(e int) string {
if e >= len(ef.names) || e < 0 {
return "Invalid"
}
return ef.names[e]
}

func (ef EnumFormatter) Parse(s string) int {
target := strings.ToLower(s)
for index, name := range ef.names {
if target == strings.ToLower(name) {
return index
}
}
return EnumInvalid
}

func CreateEnumFormatter(names []string) types.EnumFormatter {
return &EnumFormatter{
names,
}
}
7 changes: 4 additions & 3 deletions pkg/format/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ func ParseBool(value string, defaultValue bool) bool {
}

func PrintBool(value bool) string {
if(value) {
if value {
return "Yes"
} else {
return "No"
}

return "No"

}
22 changes: 22 additions & 0 deletions pkg/format/format_query.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package format

import (
"fmt"
"github.com/containrrr/shoutrrr/pkg/types"
)

// BuildQuery converts the fields of a config object to a delimited query string
func BuildQuery(c types.ServiceConfig) string {
query := ""
fields := c.QueryFields()
format := "%s=%s"
for index, key := range fields {
value, _ := c.Get(key)
if index == 1 {
format = "&%s=%s"
}
query += fmt.Sprintf(format, key, value)
}

return query
}
10 changes: 5 additions & 5 deletions pkg/format/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package format

import (
"fmt"
"github.com/containrrr/shoutrrr/pkg/plugin"
"github.com/containrrr/shoutrrr/pkg/types"
"github.com/fatih/color"
"reflect"
"strings"
)

func GetConfigMap(config plugin.PluginConfig) map[string]string {
func GetConfigMap(config types.ServiceConfig) map[string]string {
formatter := Formatter{
EnumFormatters: config.Enums(),
MaxDepth: 10,
Expand All @@ -23,7 +23,7 @@ var colorizeNumber = color.New(color.FgHiCyan).SprintFunc()
var colorizeString = color.New(color.FgHiYellow).SprintFunc()

type Formatter struct {
EnumFormatters map[string]plugin.EnumFormatter
EnumFormatters map[string]types.EnumFormatter
MaxDepth uint8
Errors []error
}
Expand Down Expand Up @@ -87,9 +87,9 @@ func (fmtr *Formatter) getFieldValueString(field reflect.Value, depth uint8) str
val := field.Bool()
if val {
return colorizeTrue(PrintBool(val))
} else {
return colorizeFalse(PrintBool(val))
}
return colorizeFalse(PrintBool(val))


case reflect.Slice:
fallthrough
Expand Down
27 changes: 0 additions & 27 deletions pkg/plugin/enumformatter.go

This file was deleted.

58 changes: 0 additions & 58 deletions pkg/plugin/plugin.go

This file was deleted.

21 changes: 0 additions & 21 deletions pkg/plugin/plugins_opts.go

This file was deleted.

85 changes: 0 additions & 85 deletions pkg/plugins/discord/discord.go

This file was deleted.

6 changes: 0 additions & 6 deletions pkg/plugins/plugins.coverprofile

This file was deleted.

Loading

0 comments on commit 2e825c7

Please sign in to comment.