From 35b2a960fc38124a0dbde849e0fcf67bcbec23c0 Mon Sep 17 00:00:00 2001 From: Thomas Boerger Date: Fri, 1 Jan 2016 21:35:10 +0100 Subject: [PATCH] Use the drone-go StringSlice instead of custom implementation --- types.go | 50 +++++++++----------------------------------------- 1 file changed, 9 insertions(+), 41 deletions(-) diff --git a/types.go b/types.go index 7831e0c..908f000 100644 --- a/types.go +++ b/types.go @@ -1,45 +1,13 @@ package main -import "encoding/json" +import ( + "github.com/drone/drone-go/drone" +) -// StrSlice representes a string or an array of strings. -// We need to override the json decoder to accept both options. -type StrSlice struct { - parts []string -} - -// UnmarshalJSON decodes the byte slice whether it's a string or an array of strings. -// This method is needed to implement json.Unmarshaler. -func (e *StrSlice) UnmarshalJSON(b []byte) error { - if len(b) == 0 { - return nil - } - - p := make([]string, 0, 1) - if err := json.Unmarshal(b, &p); err != nil { - var s string - if err := json.Unmarshal(b, &s); err != nil { - return err - } - p = append(p, s) - } - - e.parts = p - return nil -} - -// Len returns the number of parts of the StrSlice. -func (e *StrSlice) Len() int { - if e == nil { - return 0 - } - return len(e.parts) -} - -// Slice gets the parts of the StrSlice as a Slice of string. -func (e *StrSlice) Slice() []string { - if e == nil { - return nil - } - return e.parts +type Params struct { + Commands []string `json:"commands"` + Login string `json:"user"` + Port int `json:"port"` + Host drone.StringSlice `json:"host"` + Sleep int `json:"sleep"` }