Documentation
¶
Overview ¶
Package foremanhttp provides an embeddable admin JSON API for a Foreman client.
Index ¶
Examples ¶
Constants ¶
View Source
const RequestIDHeader = "X-Request-Id"
RequestIDHeader carries the request id.
Variables ¶
This section is empty.
Functions ¶
func Handler ¶
Handler returns the admin JSON API for client.
Example ¶
package main
import (
"net/http"
"github.com/thnhdatle/foreman"
"github.com/thnhdatle/foreman/foremanhttp"
)
func main() {
var client *foreman.Client
mux := http.NewServeMux()
requireAdmin := func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Header.Get("Authorization") != "Bearer secret-from-config" {
http.Error(w, "forbidden", http.StatusForbidden)
return
}
next.ServeHTTP(w, r)
})
}
mux.Handle("/admin/foreman/", requireAdmin(http.StripPrefix("/admin/foreman", foremanhttp.Handler(client))))
}
Output:
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.