| 1 |
package main |
| 2 |
|
| 3 |
import ( |
| 4 |
"fmt" |
| 5 |
"log" |
| 6 |
"net/http" |
| 7 |
"os" |
| 8 |
|
| 9 |
"github.com/slack-go/slack" |
| 10 |
) |
| 11 |
|
| 12 |
type ( |
| 13 |
appContext struct { |
| 14 |
slack *slack.Client |
| 15 |
config configuration |
| 16 |
} |
| 17 |
configuration struct { |
| 18 |
botToken string |
| 19 |
signingSecret string |
| 20 |
} |
| 21 |
SecretsVerifierMiddleware struct { |
| 22 |
handler http.Handler |
| 23 |
} |
| 24 |
) |
| 25 |
|
| 26 |
const ( |
| 27 |
APIBaseURL = "/api/v1" |
| 28 |
|
| 29 |
|
| 30 |
MyExampleWorkflowStepCallbackID = "example-step" |
| 31 |
) |
| 32 |
|
| 33 |
var appCtx appContext |
| 34 |
|
| 35 |
func main() { |
| 36 |
appCtx.config.botToken = os.Getenv("SLACK_BOT_TOKEN") |
| 37 |
appCtx.config.signingSecret = os.Getenv("SLACK_SIGNING_SECRET") |
| 38 |
|
| 39 |
appCtx.slack = slack.New(appCtx.config.botToken) |
| 40 |
|
| 41 |
mux := http.NewServeMux() |
| 42 |
mux.HandleFunc(fmt.Sprintf("%s/interaction", APIBaseURL), handleInteraction) |
| 43 |
mux.HandleFunc(fmt.Sprintf("%s/%s", APIBaseURL, MyExampleWorkflowStepCallbackID), handleMyWorkflowStep) |
| 44 |
middleware := NewSecretsVerifierMiddleware(mux) |
| 45 |
|
| 46 |
log.Printf("starting server on :8080") |
| 47 |
log.Fatal(http.ListenAndServe(":8080", middleware)) |
| 48 |
} |