├── .gitignore ├── LICENSE ├── README.md ├── client.go ├── client_test.go ├── envelope.go ├── envelope_test.go ├── response.go ├── response_test.go └── wercker.yml /.gitignore: -------------------------------------------------------------------------------- 1 | # go lang 2 | **/bin/ 3 | **/pkg/ 4 | 5 | # maven 6 | **/log/ 7 | **/target/ 8 | 9 | # eclipse 10 | **/.classpath 11 | **/.project 12 | **/.settings/ 13 | 14 | **/dataBase.properties 15 | **/logs/ 16 | **/channels/ 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 radoslav 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GoLang SOAP with WsseSecurity 2 | 3 | ## HowTo 4 | 5 | ### Sample go code: 6 | ```go 7 | package main 8 | 9 | import ( 10 | "encoding/xml" 11 | "fmt" 12 | "github.com/radoslav/soap" 13 | ) 14 | 15 | func main() { 16 | env := &soap.Envelope{ 17 | XmlnsSoapenv: "http://schemas.xmlsoap.org/soap/envelope/", 18 | XmlnsUniv: "http://www.example.pl/ws/test/universal", 19 | Header: &soap.Header{ 20 | WsseSecurity: &soap.WsseSecurity{ 21 | MustUnderstand: "1", 22 | XmlnsWsse: "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", 23 | XmlnsWsu: "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd", 24 | UsernameToken: &soap.UsernameToken{ 25 | WsuId: "UsernameToken-1", 26 | Username: &soap.Username{}, 27 | Password: &soap.Password{ 28 | Type: "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText", 29 | }, 30 | }, 31 | }, 32 | }, 33 | } 34 | 35 | env.Header.WsseSecurity.UsernameToken.Username.Value = "username" 36 | env.Header.WsseSecurity.UsernameToken.Password.Value = "pass" 37 | env.Body = &soap.Body{} // interface 38 | 39 | output, err := xml.MarshalIndent(env, "", " ") 40 | if err != nil { 41 | fmt.Printf("error: %v\n", err) 42 | } 43 | 44 | fmt.Println(string(output)) 45 | } 46 | ``` 47 | 48 | Output: 49 | 50 | ```xml 51 | 52 | 53 | 54 | 55 | username 56 | pass 57 | 58 | 59 | 60 | 61 | 62 | ``` 63 | ### Unmarshal 64 | 65 | ```go 66 | package main 67 | 68 | import ( 69 | "encoding/xml" 70 | "github.com/radoslav/soap" 71 | ) 72 | 73 | const data = ` 74 | 75 | 76 | 77 | username 78 | pass 79 | 80 | 81 | 82 | 83 | ` 84 | 85 | func main() { 86 | var env soap.ResponseEnvelope 87 | err := xml.Unmarshal([]byte(data), &env) 88 | if err != nil { 89 | panic(err) 90 | } 91 | } 92 | ``` 93 | -------------------------------------------------------------------------------- /client.go: -------------------------------------------------------------------------------- 1 | package soap 2 | 3 | import ( 4 | "bytes" 5 | "crypto/tls" 6 | "encoding/xml" 7 | "errors" 8 | "io/ioutil" 9 | "net/http" 10 | "regexp" 11 | ) 12 | 13 | func Request(url string, soapRequest []byte, soapAction string) ([]byte, error) { 14 | buffer := new(bytes.Buffer) 15 | buffer.Write(soapRequest) 16 | 17 | req, err := http.NewRequest("POST", url, buffer) 18 | if err != nil { 19 | return nil, err 20 | } 21 | 22 | req.Header.Add("Content-Type", "text/xml;charset=UTF-8") 23 | req.Header.Add("SOAPAction", soapAction) 24 | req.Header.Set("User-Agent", "github.com/radoslav/soap/0.1") 25 | req.Close = true 26 | 27 | tr := &http.Transport{ 28 | TLSClientConfig: &tls.Config{ 29 | InsecureSkipVerify: true, 30 | }, 31 | } 32 | client := &http.Client{Transport: tr} 33 | 34 | res, err := client.Do(req) 35 | if err != nil { 36 | return nil, err 37 | } 38 | defer res.Body.Close() 39 | 40 | rawbody, err := ioutil.ReadAll(res.Body) 41 | if len(rawbody) == 0 { 42 | return nil, errors.New("Empty response") 43 | } 44 | 45 | soapResponse, err := SoapFomMTOM(rawbody) 46 | if err != nil { 47 | return nil, err 48 | } 49 | 50 | // test for fault 51 | err = CheckFault(soapResponse) 52 | if err != nil { 53 | return nil, err 54 | } 55 | 56 | return soapResponse, nil 57 | } 58 | 59 | func SoapFomMTOM(soap []byte) ([]byte, error) { 60 | reg := regexp.MustCompile(`(?ims)<[env:|soap:].+Envelope>`) 61 | s := reg.FindString(string(soap)) 62 | if s == "" { 63 | return nil, errors.New("Response without soap envelope") 64 | } 65 | 66 | return []byte(s), nil 67 | } 68 | 69 | func CheckFault(soapResponse []byte) error { 70 | xmlEnvelope := ResponseEnvelope{} 71 | 72 | err := xml.Unmarshal(soapResponse, &xmlEnvelope) 73 | if err != nil { 74 | return err 75 | } 76 | 77 | fault := xmlEnvelope.ResponseBodyBody.Fault 78 | if fault.XMLName.Local == "Fault" { 79 | sFault := fault.Code + " | " + fault.String + " | " + fault.Actor + " | " + fault.Detail 80 | return errors.New(sFault) 81 | } 82 | 83 | return nil 84 | } 85 | -------------------------------------------------------------------------------- /client_test.go: -------------------------------------------------------------------------------- 1 | package soap 2 | 3 | import ( 4 | "os" 5 | ) 6 | 7 | func ExampleSoapFomMTOM() { 8 | s := []byte("dasdasd---dasdad<>adsdasfasdfsadfsaf--sadadad<>asdasd") 9 | out, _ := SoapFomMTOM(s) 10 | 11 | os.Stdout.Write(out) 12 | // Output: 13 | // adsdasfasdfsadfsaf 14 | } 15 | 16 | func ExampleSoapFomMTOM2() { 17 | s := ` 18 | HTTP/1.1 500 Internal Server Error 19 | Content-Type: text/xml; charset="utf-8" 20 | X-Backside-Transport: FAIL FAIL 21 | Connection: close 22 | 23 | 24 | 25 | 26 | env:Client 27 | Rejected (from client) 28 | 29 | 30 | 31 | 32 | <><> 33 | ` 34 | 35 | out, _ := SoapFomMTOM([]byte(s)) 36 | 37 | os.Stdout.Write(out) 38 | // Output: 39 | // 40 | // 41 | // 42 | // env:Client 43 | // Rejected (from client) 44 | // 45 | // 46 | // 47 | } 48 | -------------------------------------------------------------------------------- /envelope.go: -------------------------------------------------------------------------------- 1 | package soap 2 | 3 | import ( 4 | "encoding/xml" 5 | ) 6 | 7 | type Envelope struct { 8 | XMLName xml.Name `xml:"soapenv:Envelope"` 9 | XmlnsSoapenv string `xml:"xmlns:soapenv,attr"` 10 | XmlnsUniv string `xml:"xmlns:univ,attr"` 11 | 12 | Header *Header 13 | Body *Body 14 | } 15 | 16 | type Body struct { 17 | XMLName xml.Name `xml:"soapenv:Body"` 18 | Payload interface{} 19 | } 20 | 21 | type Header struct { 22 | XMLName xml.Name `xml:"soapenv:Header"` 23 | WsseSecurity *WsseSecurity 24 | } 25 | 26 | type WsseSecurity struct { 27 | MustUnderstand string `xml:"soapenv:mustUnderstand,attr"` 28 | XMLName xml.Name `xml:"wsse:Security"` 29 | XmlnsWsse string `xml:"xmlns:wsse,attr"` 30 | XmlnsWsu string `xml:"xmlns:wsu,attr"` 31 | 32 | UsernameToken *UsernameToken 33 | } 34 | 35 | type UsernameToken struct { 36 | XMLName xml.Name `xml:"wsse:UsernameToken"` 37 | WsuId string `xml:"wsu:Id,attr,omitempty"` 38 | Username *Username 39 | Password *Password 40 | Nonce *Nonce 41 | Created *Created 42 | } 43 | 44 | type Username struct { 45 | XMLName xml.Name `xml:"wsse:Username"` 46 | Value string `xml:",chardata"` 47 | } 48 | type Password struct { 49 | XMLName xml.Name `xml:"wsse:Password"` 50 | Type string `xml:"Type,attr"` 51 | Value string `xml:",chardata"` 52 | } 53 | type Nonce struct { 54 | XMLName xml.Name `xml:"wsse:Nonce,omitempty"` 55 | EncodingType string `xml:"EncodingType,attr,omitempty"` 56 | Value string `xml:",chardata"` 57 | } 58 | type Created struct { 59 | XMLName xml.Name `xml:"wsu:Created,omitempty"` 60 | Value string `xml:",chardata"` 61 | } 62 | -------------------------------------------------------------------------------- /envelope_test.go: -------------------------------------------------------------------------------- 1 | package soap 2 | 3 | import ( 4 | "encoding/xml" 5 | "fmt" 6 | "os" 7 | ) 8 | 9 | const prefix string = "" 10 | const indent string = " " 11 | const namespaceUniv = "http://www.example.pl/ws/test/universal" 12 | 13 | func ExampleBody() { 14 | env := &Envelope{ 15 | XmlnsSoapenv: "http://schemas.xmlsoap.org/soap/envelope/", 16 | XmlnsUniv: namespaceUniv, 17 | } 18 | 19 | env.Body = &Body{} 20 | 21 | output, err := xml.MarshalIndent(env, prefix, indent) 22 | if err != nil { 23 | fmt.Printf("error: %v\n", err) 24 | } 25 | 26 | os.Stdout.Write(output) 27 | // Output: 28 | // 29 | // 30 | // 31 | } 32 | 33 | func ExampleEnvelope() { 34 | env := &Envelope{ 35 | XmlnsSoapenv: "http://schemas.xmlsoap.org/soap/envelope/", 36 | XmlnsUniv: namespaceUniv, 37 | } 38 | 39 | output, err := xml.MarshalIndent(env, prefix, indent) 40 | if err != nil { 41 | fmt.Printf("error: %v\n", err) 42 | } 43 | 44 | os.Stdout.Write(output) 45 | // Output: 46 | // 47 | } 48 | 49 | func ExampleHeader() { 50 | env := &Envelope{ 51 | XmlnsSoapenv: "http://schemas.xmlsoap.org/soap/envelope/", 52 | XmlnsUniv: namespaceUniv, 53 | Header: &Header{}, 54 | } 55 | 56 | output, err := xml.MarshalIndent(env, prefix, indent) 57 | if err != nil { 58 | fmt.Printf("error: %v\n", err) 59 | } 60 | 61 | os.Stdout.Write(output) 62 | // Output: 63 | // 64 | // 65 | // 66 | } 67 | 68 | func ExampleWsseSecurity() { 69 | env := &Envelope{ 70 | XmlnsSoapenv: "http://schemas.xmlsoap.org/soap/envelope/", 71 | XmlnsUniv: namespaceUniv, 72 | Header: &Header{ 73 | WsseSecurity: &WsseSecurity{ 74 | MustUnderstand: "1", 75 | XmlnsWsse: "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", 76 | XmlnsWsu: "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd", 77 | }, 78 | }, 79 | } 80 | 81 | output, err := xml.MarshalIndent(env, prefix, indent) 82 | if err != nil { 83 | fmt.Printf("error: %v\n", err) 84 | } 85 | 86 | os.Stdout.Write(output) 87 | // Output: 88 | // 89 | // 90 | // 91 | // 92 | // 93 | 94 | } 95 | 96 | func ExampleUsernameToken() { 97 | env := &Envelope{ 98 | XmlnsSoapenv: "http://schemas.xmlsoap.org/soap/envelope/", 99 | XmlnsUniv: namespaceUniv, 100 | Header: &Header{ 101 | WsseSecurity: &WsseSecurity{ 102 | MustUnderstand: "1", 103 | XmlnsWsse: "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", 104 | XmlnsWsu: "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd", 105 | UsernameToken: &UsernameToken{ 106 | WsuId: "UsernameToken-1", 107 | }, 108 | }, 109 | }, 110 | } 111 | 112 | output, err := xml.MarshalIndent(env, prefix, indent) 113 | if err != nil { 114 | fmt.Printf("error: %v\n", err) 115 | } 116 | 117 | os.Stdout.Write(output) 118 | // Output: 119 | // 120 | // 121 | // 122 | // 123 | // 124 | // 125 | // 126 | 127 | } 128 | 129 | func ExampleUsername() { 130 | env := &Envelope{ 131 | XmlnsSoapenv: "http://schemas.xmlsoap.org/soap/envelope/", 132 | XmlnsUniv: namespaceUniv, 133 | Header: &Header{ 134 | WsseSecurity: &WsseSecurity{ 135 | MustUnderstand: "1", 136 | XmlnsWsse: "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", 137 | XmlnsWsu: "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd", 138 | UsernameToken: &UsernameToken{ 139 | WsuId: "UsernameToken-1", 140 | Username: &Username{}, 141 | }, 142 | }, 143 | }, 144 | } 145 | 146 | env.Header.WsseSecurity.UsernameToken.Username.Value = "test" 147 | 148 | output, err := xml.MarshalIndent(env, prefix, indent) 149 | if err != nil { 150 | fmt.Printf("error: %v\n", err) 151 | } 152 | 153 | os.Stdout.Write(output) 154 | // Output: 155 | // 156 | // 157 | // 158 | // 159 | // test 160 | // 161 | // 162 | // 163 | // 164 | 165 | } 166 | 167 | func ExamplePassword() { 168 | env := &Envelope{ 169 | XmlnsSoapenv: "http://schemas.xmlsoap.org/soap/envelope/", 170 | XmlnsUniv: namespaceUniv, 171 | Header: &Header{ 172 | WsseSecurity: &WsseSecurity{ 173 | MustUnderstand: "1", 174 | XmlnsWsse: "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", 175 | XmlnsWsu: "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd", 176 | UsernameToken: &UsernameToken{ 177 | WsuId: "UsernameToken-1", 178 | Password: &Password{ 179 | Type: "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText", 180 | }, 181 | }, 182 | }, 183 | }, 184 | } 185 | 186 | env.Header.WsseSecurity.UsernameToken.Password.Value = "pass" 187 | 188 | output, err := xml.MarshalIndent(env, prefix, indent) 189 | if err != nil { 190 | fmt.Printf("error: %v\n", err) 191 | } 192 | 193 | os.Stdout.Write(output) 194 | // Output: 195 | // 196 | // 197 | // 198 | // 199 | // pass 200 | // 201 | // 202 | // 203 | // 204 | 205 | } 206 | 207 | func ExampleNonce() { 208 | env := &Envelope{ 209 | XmlnsSoapenv: "http://schemas.xmlsoap.org/soap/envelope/", 210 | XmlnsUniv: namespaceUniv, 211 | Header: &Header{ 212 | WsseSecurity: &WsseSecurity{ 213 | MustUnderstand: "1", 214 | XmlnsWsse: "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", 215 | XmlnsWsu: "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd", 216 | UsernameToken: &UsernameToken{ 217 | WsuId: "UsernameToken-1", 218 | Username: &Username{}, 219 | Password: &Password{ 220 | Type: "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText", 221 | }, 222 | Nonce: &Nonce{ 223 | EncodingType: "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary", 224 | }, 225 | }, 226 | }, 227 | }, 228 | } 229 | 230 | env.Header.WsseSecurity.UsernameToken.Username.Value = "test" 231 | env.Header.WsseSecurity.UsernameToken.Password.Value = "pass" 232 | env.Header.WsseSecurity.UsernameToken.Nonce.Value = "nvKKZ20LNP8wpCa4vAeQhQ==" 233 | 234 | output, err := xml.MarshalIndent(env, prefix, indent) 235 | if err != nil { 236 | fmt.Printf("error: %v\n", err) 237 | } 238 | 239 | os.Stdout.Write(output) 240 | // Output: 241 | // 242 | // 243 | // 244 | // 245 | // test 246 | // pass 247 | // nvKKZ20LNP8wpCa4vAeQhQ== 248 | // 249 | // 250 | // 251 | // 252 | 253 | } 254 | 255 | func ExampleCreated() { 256 | env := &Envelope{ 257 | XmlnsSoapenv: "http://schemas.xmlsoap.org/soap/envelope/", 258 | XmlnsUniv: namespaceUniv, 259 | Header: &Header{ 260 | WsseSecurity: &WsseSecurity{ 261 | MustUnderstand: "1", 262 | XmlnsWsse: "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", 263 | XmlnsWsu: "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd", 264 | UsernameToken: &UsernameToken{ 265 | WsuId: "UsernameToken-1", 266 | Username: &Username{}, 267 | Password: &Password{ 268 | Type: "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText", 269 | }, 270 | Nonce: &Nonce{ 271 | EncodingType: "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary", 272 | }, 273 | Created: &Created{}, 274 | }, 275 | }, 276 | }, 277 | } 278 | 279 | env.Header.WsseSecurity.UsernameToken.Username.Value = "test" 280 | env.Header.WsseSecurity.UsernameToken.Password.Value = "pass" 281 | env.Header.WsseSecurity.UsernameToken.Nonce.Value = "nvKKZ20LNP8wpCa4vAeQhQ==" 282 | env.Header.WsseSecurity.UsernameToken.Created.Value = "2015-09-10T12:25:55.121Z" 283 | 284 | output, err := xml.MarshalIndent(env, prefix, indent) 285 | if err != nil { 286 | fmt.Printf("error: %v\n", err) 287 | } 288 | 289 | os.Stdout.Write(output) 290 | // Output: 291 | // 292 | // 293 | // 294 | // 295 | // test 296 | // pass 297 | // nvKKZ20LNP8wpCa4vAeQhQ== 298 | // 2015-09-10T12:25:55.121Z 299 | // 300 | // 301 | // 302 | // 303 | 304 | } 305 | -------------------------------------------------------------------------------- /response.go: -------------------------------------------------------------------------------- 1 | package soap 2 | 3 | import ( 4 | "encoding/xml" 5 | ) 6 | 7 | type ResponseEnvelope struct { 8 | XMLName xml.Name `xml:"http://schemas.xmlsoap.org/soap/envelope/ Envelope"` 9 | ResponseBodyBody ResponseBody `xml:"http://schemas.xmlsoap.org/soap/envelope/ Body"` 10 | } 11 | 12 | type ResponseBody struct { 13 | XMLName xml.Name `xml:"http://schemas.xmlsoap.org/soap/envelope/ Body"` 14 | Fault Fault `xml:"http://schemas.xmlsoap.org/soap/envelope/ Fault"` 15 | } 16 | 17 | type Fault struct { 18 | XMLName xml.Name `xml:"http://schemas.xmlsoap.org/soap/envelope/ Fault"` 19 | Code string `xml:"faultcode,omitempty"` 20 | String string `xml:"faultstring,omitempty"` 21 | Actor string `xml:"faultactor,omitempty"` 22 | Detail string `xml:"detail,omitempty"` 23 | } 24 | -------------------------------------------------------------------------------- /response_test.go: -------------------------------------------------------------------------------- 1 | package soap 2 | 3 | import ( 4 | "encoding/json" 5 | "encoding/xml" 6 | "os" 7 | "testing" 8 | ) 9 | 10 | func ExampleResponse() { 11 | s := ` 12 | 13 | 14 | 15 | env:Client 16 | Rejected (from client) 17 | 18 | 19 | ` 20 | 21 | soapTest := []byte(s) 22 | 23 | env := ResponseEnvelope{} 24 | 25 | xml.Unmarshal(soapTest, &env) 26 | 27 | json, _ := json.Marshal(env) 28 | os.Stdout.Write(json) 29 | 30 | // Output: 31 | // {"XMLName":{"Space":"http://schemas.xmlsoap.org/soap/envelope/","Local":"Envelope"},"ResponseBodyBody":{"XMLName":{"Space":"http://schemas.xmlsoap.org/soap/envelope/","Local":"Body"},"Fault":{"XMLName":{"Space":"http://schemas.xmlsoap.org/soap/envelope/","Local":"Fault"},"Code":"env:Client","String":"Rejected (from client)","Actor":"","Detail":""}}} 32 | 33 | } 34 | 35 | func TestResponseFault(t *testing.T) { 36 | s := ` 37 | 38 | 39 | 40 | env:Client 41 | Rejected (from client) 42 | 43 | 44 | ` 45 | 46 | soapTest := []byte(s) 47 | 48 | err := CheckFault(soapTest) 49 | if err == nil { 50 | t.Error("Expected fault") 51 | } 52 | 53 | } 54 | 55 | func TestResponseNotFault(t *testing.T) { 56 | s := `` 57 | soapTest := []byte(s) 58 | 59 | err := CheckFault(soapTest) 60 | if err != nil { 61 | t.Error("Expected positive") 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /wercker.yml: -------------------------------------------------------------------------------- 1 | # This references the default golang container from 2 | # the Docker Hub: https://registry.hub.docker.com/u/library/golang/ 3 | # If you want Google's container you would reference google/golang 4 | # Read more about containers on our dev center 5 | # http://devcenter.wercker.com/docs/containers/index.html 6 | box: golang 7 | # This is the build pipeline. Pipelines are the core of wercker 8 | # Read more about pipelines on our dev center 9 | # http://devcenter.wercker.com/docs/pipelines/index.html 10 | 11 | # You can also use services such as databases. Read more on our dev center: 12 | # http://devcenter.wercker.com/docs/services/index.html 13 | # services: 14 | # - postgres 15 | # http://devcenter.wercker.com/docs/services/postgresql.html 16 | 17 | # - mongodb 18 | # http://devcenter.wercker.com/docs/services/mongodb.html 19 | build: 20 | # The steps that will be executed on build 21 | # Steps make up the actions in your pipeline 22 | # Read more about steps on our dev center: 23 | # http://devcenter.wercker.com/docs/steps/index.html 24 | steps: 25 | # Sets the go workspace and places you package 26 | # at the right place in the workspace tree 27 | - setup-go-workspace 28 | 29 | # Gets the dependencies 30 | - script: 31 | name: go get 32 | code: | 33 | go get 34 | 35 | # Build the project 36 | - script: 37 | name: go build 38 | code: | 39 | go build ./... 40 | 41 | # Test the project 42 | - script: 43 | name: go test 44 | code: | 45 | go test ./... 46 | 47 | deploy: 48 | steps: 49 | - script: 50 | name: pwd 51 | code: | 52 | echo ".... PWD ..." 53 | pwd 54 | ls -la 55 | --------------------------------------------------------------------------------