Skip to content

Commit

Permalink
Merge pull request #1 from sgarcez/refactor
Browse files Browse the repository at this point in the history
Refactor
  • Loading branch information
sgarcez authored Aug 27, 2018
2 parents a8c9842 + 67832f4 commit 4796b5d
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
*.out

/dist
/cmd/sul/sul
sul
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
builds:
- env:
- CGO_ENABLED=0
main: ./cmd/sul/main.go
main: ./main.go
binary: sul
goos:
- linux
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ $ curl -L https://github.com/sgarcez/sul/releases/download/v0.0.2/sul_0.0.2_Linu
### Using go get

```shell
$ go get -u github.com/sgarcez/sul/cmd/sul
$ go get -u github.com/sgarcez/sul
```

## Usage
Expand Down
6 changes: 3 additions & 3 deletions auth.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sul
package main

import (
"fmt"
Expand All @@ -7,8 +7,8 @@ import (
"github.com/strava/go.strava"
)

// Handler provides an auth url and HandlerFunc to handle its redirect
func Handler(port string) (string, string, http.HandlerFunc, error) {
// AuthHandler provides an auth url and HandlerFunc to handle its redirect
func AuthHandler(port string) (string, string, http.HandlerFunc, error) {

// Application id and secret can be found at https://www.strava.com/settings/api
// define a strava.OAuthAuthenticator to hold state.
Expand Down
8 changes: 8 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module github.com/sgarcez/sul

require (
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/spf13/cobra v0.0.3
github.com/spf13/pflag v1.0.2 // indirect
github.com/strava/go.strava v0.0.0-20180612235916-99ebe972ba16
)
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/spf13/cobra v0.0.3 h1:ZlrZ4XsMRm04Fr5pSFxBgfND2EBVa1nLpiy1stUsX/8=
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/pflag v1.0.2 h1:Fy0orTDgHdbnzHcsOgfCN4LtHf0ec3wwtiwJqwvf3Gc=
github.com/spf13/pflag v1.0.2/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/strava/go.strava v0.0.0-20180612235916-99ebe972ba16 h1:EByiQtVco26j69tJGwr2EaeM+6AFJvz9hR6VwEWeUFQ=
github.com/strava/go.strava v0.0.0-20180612235916-99ebe972ba16/go.mod h1:M6HqlQU01mCWZxTUI0n9XMxUOsJQpCwJbyq/w1j/Lkg=
7 changes: 3 additions & 4 deletions cmd/sul/main.go → main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"path"
"sync"

"github.com/sgarcez/sul"
"github.com/spf13/cobra"
strava "github.com/strava/go.strava"
)
Expand All @@ -37,7 +36,7 @@ func new() *cobra.Command {
Short: "Uploads activity files from directory",
Run: func(cmd *cobra.Command, args []string) {
accessToken := cmd.Flag("token").Value.String()
u := sul.NewUploader(accessToken)
u := NewUploader(accessToken)

inputDir := cmd.Flag("dir").Value.String()
files, err := ioutil.ReadDir(inputDir)
Expand Down Expand Up @@ -83,7 +82,7 @@ func new() *cobra.Command {

m := http.NewServeMux()
s := &http.Server{Addr: fmt.Sprintf(":%s", port), Handler: m}
authURL, callbackPath, callbackHandler, err := sul.Handler(port)
authURL, callbackPath, callbackHandler, err := AuthHandler(port)
if err != nil {
log.Fatal(err)
}
Expand All @@ -101,7 +100,7 @@ func new() *cobra.Command {
m.HandleFunc(callbackPath, handleAndKill(callbackHandler))

fmt.Printf("-------------------------------\n")
fmt.Printf("Open this URL to authorise your application:\n\n%s\n", authURL)
fmt.Printf("Use this URL to authorise your application:\n\n%s\n", authURL)
fmt.Printf("-------------------------------\n")

if err := s.ListenAndServe(); err != nil && err != http.ErrServerClosed {
Expand Down
2 changes: 1 addition & 1 deletion uploader.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sul
package main

import (
"io"
Expand Down

0 comments on commit 4796b5d

Please sign in to comment.