-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Urban Ishimwe
committed
Apr 20, 2020
1 parent
dc1d1e2
commit 2d8bfc2
Showing
9 changed files
with
138 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package route | ||
|
||
import ( | ||
"os" | ||
) | ||
|
||
// ADDR of the server | ||
var ADDR string | ||
|
||
func init() { | ||
addr := os.Getenv("PORT") | ||
if addr == "" { | ||
ADDR = ":8080" | ||
return | ||
} | ||
ADDR = ":" + addr | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package route | ||
|
||
// import ( | ||
// "net/http" | ||
|
||
// "github.com/gorilla/mux" | ||
// ) | ||
|
||
// func CommandRoute(r *mux.Route) { | ||
// r.HandlerFunc().Methods(http.MethodPost) | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,38 @@ | ||
package route | ||
|
||
import ( | ||
"net/http" | ||
"os" | ||
|
||
"github.com/gorilla/mux" | ||
) | ||
|
||
var R *mux.Router | ||
|
||
// Router the | ||
func Router() *mux.Router { | ||
R := mux.NewRouter() | ||
return R | ||
var origin = os.Getenv("ORIGIN") | ||
if origin == "" { | ||
origin = "*" | ||
} | ||
|
||
r := mux.NewRouter() | ||
|
||
// HOME ROUTE == PONG | ||
r.HandleFunc("/", func(rw http.ResponseWriter, _ *http.Request) { | ||
rw.Write([]byte("PONG")) | ||
}).Methods(http.MethodGet, http.MethodPost) | ||
|
||
// OPTIONS request | ||
r.Methods(http.MethodOptions).HandlerFunc(func(rw http.ResponseWriter, _ *http.Request) { | ||
rw.Header().Set("Access-Control-Allow-Methods", "POST, GET, PUT, OPTIONS, DELETE") | ||
rw.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization") | ||
rw.Header().Set("Access-Control-Allow-Origin", origin) | ||
rw.Header().Set("Access-Control-Allow-Credentials", "true") | ||
rw.WriteHeader(http.StatusNoContent) | ||
}) | ||
|
||
r.HandleFunc("*", func(rw http.ResponseWriter, _ *http.Request) { | ||
rw.WriteHeader(http.StatusNotFound) | ||
}).Methods(http.MethodGet, http.MethodPost) | ||
|
||
return r | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package slack | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
) | ||
|
||
// InstallHTML return html for installing app | ||
func InstallHTML() string { | ||
slackClientID := os.Getenv("SLACK_CLIENT_ID") | ||
port := os.Getenv("PORT") | ||
if port == "" { | ||
port = "8080" | ||
} | ||
host := "http://localhost:" + port | ||
return fmt.Sprintf(` | ||
<html lang="en"> | ||
<head> | ||
<title> Install slack </tile> | ||
</head> | ||
<h1> Install this app in your slack workspace </h1> | ||
<a href="https://slack.com/oauth/authorize?client_id=%s&scope=im:write,chat:write,users:read,reactions:read&redirect_uri=%s" | ||
</html> | ||
`, slackClientID) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package slack | ||
|
||
import ( | ||
"net/http" | ||
"os" | ||
|
||
"github.com/slack-go/slack" | ||
) | ||
|
||
var ( | ||
slackClientID = os.Getenv("SLACK_CLIENT_ID") | ||
slackClientSecret = os.Getenv("SLACK_CLIENT_SECRET") | ||
) | ||
|
||
// OAuthToken return slack authentication on a worskpace | ||
func OAuthToken(code string, redirectURI string) (string, string, error) { | ||
return slack.GetOAuthToken(http.DefaultClient, slackClientID, slackClientSecret, code, redirectURI) | ||
} |