@@ -9,16 +9,16 @@ import (
99 "crypto/sha256"
1010 "crypto/x509"
1111 "encoding/base64"
12- "encoding/pem"
1312 "encoding/json"
13+ "encoding/pem"
1414 "errors"
1515 "io/ioutil"
1616 "log"
1717 "net/http"
1818 "net/url"
1919 "os"
20- "strings"
2120 "strconv"
21+ "strings"
2222 "sync"
2323 "time"
2424)
@@ -29,7 +29,7 @@ const (
2929 OAUTH_URI = "https://login.salesforce.com/services/oauth2/token"
3030 POLL_INTERVAL = 30 * time .Second
3131 SDK_VERSION = "1.0.0"
32- USER_AGENT = "ApexServerClient/" + SDK_VERSION
32+ USER_AGENT = "ApexServerClient/" + SDK_VERSION
3333 HTTP_TIMEOUT = 30 * time .Second
3434)
3535
@@ -78,7 +78,7 @@ func newBridge() (*Bridge, error) {
7878 if bridge .oauthId == "" {
7979 return nil , errors .New ("OAUTH_ID not set" )
8080 }
81-
81+
8282 oauthURIString := os .Getenv ("OAUTH_URI" )
8383 if oauthURIString == "" {
8484 oauthURIString = OAUTH_URI
@@ -140,7 +140,7 @@ func newBridge() (*Bridge, error) {
140140
141141 context , cancel := context .WithCancel (context .Background ())
142142 bridge .context = context
143- bridge .cancel = cancel
143+ bridge .cancel = cancel
144144
145145 return & bridge , nil
146146}
@@ -152,18 +152,18 @@ type AuthBody struct {
152152type JWTClaim struct {
153153 ISS string `json:"iss"`
154154 Sub string `json:"sub"`
155- Aud string `json:"aud"`
155+ Aud string `json:"aud"`
156156 Exp string `json:"exp"`
157157}
158158
159159func (bridge * Bridge ) makeJWT () (* string , error ) {
160- var claim JWTClaim ;
160+ var claim JWTClaim
161161
162162 claim .ISS = bridge .oauthId
163163 claim .Sub = bridge .oauthUsername
164164 claim .Aud = bridge .oauthURI .Host
165- claim .Exp = strconv .FormatInt (time .Now ().Unix () + (60 * 2 ), 10 )
166-
165+ claim .Exp = strconv .FormatInt (time .Now ().Unix ()+ (60 * 2 ), 10 )
166+
167167 bytesClaim , err := json .Marshal (claim )
168168 if err != nil {
169169 return nil , err
@@ -203,7 +203,7 @@ func (bridge *Bridge) authorizeSalesforce() (error, bool) {
203203 query .Add ("password" , bridge .oauthPassword )
204204 }
205205
206- authRequest , err := http .NewRequest ("POST" , OAUTH_URI , strings .NewReader (query .Encode ()))
206+ authRequest , err := http .NewRequest ("POST" , bridge . oauthURI . String () , strings .NewReader (query .Encode ()))
207207 if err != nil {
208208 return err , true
209209 }
@@ -230,7 +230,7 @@ func (bridge *Bridge) authorizeSalesforce() (error, bool) {
230230 return err , false
231231 }
232232
233- var parsed AuthBody ;
233+ var parsed AuthBody
234234 json .Unmarshal (errorBody , & parsed )
235235 if parsed .AccessToken == "" {
236236 return errors .New ("expected access token in body" ), false
@@ -248,7 +248,7 @@ func (bridge *Bridge) requestWithOauth(request *http.Request) (*http.Response, e
248248 token := bridge .oauthCurrentToken
249249 bridge .lock .Unlock ()
250250
251- request .Header .Set ("Authorization" , "Bearer " + token )
251+ request .Header .Set ("Authorization" , "Bearer " + token )
252252
253253 response , err := bridge .client .Do (request )
254254 if err != nil {
@@ -288,16 +288,16 @@ func (bridge *Bridge) eventLoop() error {
288288 log .Print ("poll events expected 200 but got " , pollResponse .StatusCode )
289289 goto End
290290 }
291-
291+
292292 pollBytes , err := ioutil .ReadAll (pollResponse .Body )
293293 if err != nil {
294294 log .Print ("failed to read poll events response body" )
295- goto End;
295+ goto End
296296 }
297297
298298 if bytes .Equal (pollBytes , []byte ("[]" )) {
299299 log .Print ("No new events skipping delivery" )
300- goto End;
300+ goto End
301301 }
302302
303303 pushRequest , err := http .NewRequest ("POST" , pushURI , bytes .NewBuffer (pollBytes ))
@@ -324,7 +324,7 @@ func (bridge *Bridge) eventLoop() error {
324324 }
325325
326326 if pushResponse .StatusCode != 200 && pushResponse .StatusCode != 202 {
327- log .Print ("event push expected 200/202 got: " , pushResponse .StatusCode );
327+ log .Print ("event push expected 200/202 got: " , pushResponse .StatusCode )
328328 goto End
329329 }
330330 }
@@ -338,7 +338,6 @@ func (bridge *Bridge) eventLoop() error {
338338 case <- time .After (POLL_INTERVAL ):
339339 }
340340 }
341- return nil
342341}
343342
344343func (bridge * Bridge ) featureLoop () error {
@@ -426,21 +425,20 @@ func (bridge *Bridge) featureLoop() error {
426425 case <- time .After (POLL_INTERVAL ):
427426 }
428427 }
429- return nil
430428}
431429
432430func (bridge * Bridge ) run () error {
433431 err , _ := bridge .authorizeSalesforce ()
434432 if err != nil {
435433 return err
436434 }
437-
435+
438436 c := make (chan error )
439- go func (){
437+ go func () {
440438 c <- bridge .eventLoop ()
441439 bridge .cancel ()
442440 }()
443- go func (){
441+ go func () {
444442 c <- bridge .featureLoop ()
445443 bridge .cancel ()
446444 }()
0 commit comments