Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
func WithPrefix ¶
WithPrefix allows you to specify a custom prefix in the URL path for the server. By default, "/api" is used
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Example ¶
package main import ( "context" "encoding/json" "net/http" "os" "time" slack "github.com/lestrrat-go/slack" "github.com/lestrrat-go/slack/server" ) func main() { s := server.New() s.Handle("channels.info", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { // You can do what you want in this handler. Here, we're just // going to parse the request, and then print it out if err := r.ParseForm(); err != nil { http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest) return } var c slack.ChannelsInfoCall if err := c.FromValues(r.Form); err != nil { http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest) return } json.NewEncoder(os.Stdout).Encode(c) w.WriteHeader(http.StatusNoContent) })) var hs http.Server hs.Addr = ":9090" hs.Handler = s go hs.ListenAndServe() ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() hs.Shutdown(ctx) }
Output:
Click to show internal directories.
Click to hide internal directories.