mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
server, examples, extensions lint compliant (#1109)
these are all automated changes suggested by golint
This commit is contained in:
@@ -6,12 +6,12 @@ import (
|
||||
"os"
|
||||
)
|
||||
|
||||
type Person struct {
|
||||
type person struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
func main() {
|
||||
p := &Person{Name: "World"}
|
||||
p := &person{Name: "World"}
|
||||
json.NewDecoder(os.Stdin).Decode(p)
|
||||
mapD := map[string]string{
|
||||
"message": fmt.Sprintf("Hello %s", p.Name),
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"os"
|
||||
)
|
||||
|
||||
type Link struct {
|
||||
type link struct {
|
||||
Text string
|
||||
Href string
|
||||
}
|
||||
@@ -42,14 +42,14 @@ func main() {
|
||||
data := struct {
|
||||
Title string
|
||||
Body string
|
||||
Items []Link
|
||||
Items []link
|
||||
}{
|
||||
Title: "My App",
|
||||
Body: "This is my app. It may not be the best app, but it's my app. And it's multilingual!",
|
||||
Items: []Link{
|
||||
Link{"Ruby", fmt.Sprintf("/r/%s/ruby", appName)},
|
||||
Link{"Node", fmt.Sprintf("/r/%s/node", appName)},
|
||||
Link{"Python", fmt.Sprintf("/r/%s/python", appName)},
|
||||
Items: []link{
|
||||
link{"Ruby", fmt.Sprintf("/r/%s/ruby", appName)},
|
||||
link{"Node", fmt.Sprintf("/r/%s/node", appName)},
|
||||
link{"Python", fmt.Sprintf("/r/%s/python", appName)},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -15,51 +15,48 @@ func main() {
|
||||
|
||||
funcServer := server.NewFromEnv(ctx)
|
||||
// Setup your custom extensions, listeners, etc here
|
||||
funcServer.AddEndpoint("GET", "/custom1", &Custom1Handler{})
|
||||
funcServer.AddEndpoint("GET", "/custom1", &custom1Handler{})
|
||||
funcServer.AddEndpointFunc("GET", "/custom2", func(w http.ResponseWriter, r *http.Request) {
|
||||
// fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path))
|
||||
fmt.Println("Custom2Handler called")
|
||||
fmt.Println("custom2Handler called")
|
||||
fmt.Fprintf(w, "Hello func, %q", html.EscapeString(r.URL.Path))
|
||||
})
|
||||
|
||||
// the following will be at /v1/apps/:app_name/custom2
|
||||
funcServer.AddAppEndpoint("GET", "/custom3", &Custom3Handler{})
|
||||
funcServer.AddAppEndpoint("GET", "/custom3", &custom3Handler{})
|
||||
funcServer.AddAppEndpointFunc("GET", "/custom4", func(w http.ResponseWriter, r *http.Request, app *models.App) {
|
||||
// fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path))
|
||||
fmt.Println("Custom4Handler called")
|
||||
fmt.Println("custom4Handler called")
|
||||
fmt.Fprintf(w, "Hello app %v func, %q", app.Name, html.EscapeString(r.URL.Path))
|
||||
})
|
||||
// the following will be at /v1/apps/:app_name/routes/:route_name/custom5
|
||||
// and /v1/apps/:app_name/routes/:route_name/custom6
|
||||
funcServer.AddRouteEndpoint("GET", "/custom5", &Custom5Handler{})
|
||||
funcServer.AddRouteEndpoint("GET", "/custom5", &custom5Handler{})
|
||||
funcServer.AddRouteEndpointFunc("GET", "/custom6", func(w http.ResponseWriter, r *http.Request, app *models.App, route *models.Route) {
|
||||
// fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path))
|
||||
fmt.Println("Custom6Handler called")
|
||||
fmt.Println("custom6Handler called")
|
||||
fmt.Fprintf(w, "Hello app %v, route %v, request %q", app.Name, route.Path, html.EscapeString(r.URL.Path))
|
||||
})
|
||||
funcServer.Start(ctx)
|
||||
}
|
||||
|
||||
type Custom1Handler struct {
|
||||
}
|
||||
type custom1Handler struct{}
|
||||
|
||||
func (h *Custom1Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Println("Custom1Handler called")
|
||||
func (h *custom1Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Println("custom1Handler called")
|
||||
fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path))
|
||||
}
|
||||
|
||||
type Custom3Handler struct {
|
||||
}
|
||||
type custom3Handler struct{}
|
||||
|
||||
func (h *Custom3Handler) ServeHTTP(w http.ResponseWriter, r *http.Request, app *models.App) {
|
||||
fmt.Println("Custom3Handler called")
|
||||
func (h *custom3Handler) ServeHTTP(w http.ResponseWriter, r *http.Request, app *models.App) {
|
||||
fmt.Println("custom3Handler called")
|
||||
fmt.Fprintf(w, "Hello app %v, %q", app.Name, html.EscapeString(r.URL.Path))
|
||||
}
|
||||
|
||||
type Custom5Handler struct {
|
||||
}
|
||||
type custom5Handler struct{}
|
||||
|
||||
func (h *Custom5Handler) ServeHTTP(w http.ResponseWriter, r *http.Request, app *models.App, route *models.Route) {
|
||||
fmt.Println("Custom5Handler called")
|
||||
func (h *custom5Handler) ServeHTTP(w http.ResponseWriter, r *http.Request, app *models.App, route *models.Route) {
|
||||
fmt.Println("custom5Handler called")
|
||||
fmt.Fprintf(w, "Hello! app %v, route %v, request %q", app.Name, route.Path, html.EscapeString(r.URL.Path))
|
||||
}
|
||||
|
||||
@@ -6,12 +6,12 @@ import (
|
||||
"os"
|
||||
)
|
||||
|
||||
type Person struct {
|
||||
type person struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
func main() {
|
||||
p := &Person{Name: "World"}
|
||||
p := &person{Name: "World"}
|
||||
json.NewDecoder(os.Stdin).Decode(p)
|
||||
mapD := map[string]string{"message": fmt.Sprintf("Hello %s", p.Name)}
|
||||
mapD["SECRET_1"] = os.Getenv("SECRET_1")
|
||||
|
||||
@@ -25,15 +25,14 @@ func main() {
|
||||
})
|
||||
})
|
||||
|
||||
funcServer.AddMiddleware(&CustomMiddleware{})
|
||||
funcServer.AddMiddleware(&customMiddleware{})
|
||||
|
||||
funcServer.Start(ctx)
|
||||
}
|
||||
|
||||
type CustomMiddleware struct {
|
||||
}
|
||||
type customMiddleware struct{}
|
||||
|
||||
func (h *CustomMiddleware) Handle(next http.Handler) http.Handler {
|
||||
func (h *customMiddleware) Handle(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Println("CustomMiddleware called")
|
||||
|
||||
@@ -48,7 +47,9 @@ func (h *CustomMiddleware) Handle(next http.Handler) http.Handler {
|
||||
return
|
||||
}
|
||||
fmt.Println("auth succeeded!")
|
||||
r = r.WithContext(context.WithValue(r.Context(), "user", "I'm in!"))
|
||||
r = r.WithContext(context.WithValue(r.Context(), contextKey("user"), "I'm in!"))
|
||||
next.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
|
||||
type contextKey string
|
||||
|
||||
@@ -7,19 +7,12 @@ import (
|
||||
"os"
|
||||
)
|
||||
|
||||
type Person struct {
|
||||
type person struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
// b, err := ioutil.ReadAll(os.Stdin)
|
||||
// if err != nil {
|
||||
// log.Fatal(err)
|
||||
// }
|
||||
// fmt.Printf("BODY!!! %s", string(b))
|
||||
|
||||
p := &Person{Name: "World"}
|
||||
p := &person{Name: "World"}
|
||||
json.NewDecoder(os.Stdin).Decode(p)
|
||||
fmt.Printf("Hello %v!\n", p.Name)
|
||||
|
||||
|
||||
@@ -7,12 +7,12 @@ import (
|
||||
"os"
|
||||
)
|
||||
|
||||
type Person struct {
|
||||
type person struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
func main() {
|
||||
p := &Person{Name: "World"}
|
||||
p := &person{Name: "World"}
|
||||
json.NewDecoder(os.Stdin).Decode(p)
|
||||
mapD := map[string]string{"message": fmt.Sprintf("Hello %s", p.Name)}
|
||||
mapB, _ := json.Marshal(mapD)
|
||||
|
||||
@@ -7,12 +7,12 @@ import (
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type Person struct {
|
||||
type person struct {
|
||||
Name string
|
||||
}
|
||||
|
||||
func main() {
|
||||
p := &Person{Name: "World"}
|
||||
p := &person{Name: "World"}
|
||||
json.NewDecoder(os.Stdin).Decode(p)
|
||||
logrus.Printf("Hello %v!\n", p.Name)
|
||||
|
||||
|
||||
@@ -9,11 +9,11 @@ import (
|
||||
|
||||
const lBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
|
||||
type OutputSize struct {
|
||||
type outputSize struct {
|
||||
Size int `json:"size"`
|
||||
}
|
||||
|
||||
func RandStringBytes(n int) string {
|
||||
func randStringBytes(n int) string {
|
||||
b := make([]byte, n)
|
||||
for i := range b {
|
||||
b[i] = lBytes[rand.Intn(len(lBytes))]
|
||||
@@ -22,7 +22,7 @@ func RandStringBytes(n int) string {
|
||||
}
|
||||
|
||||
func main() {
|
||||
out := &OutputSize{Size: 64 * 1024}
|
||||
out := &outputSize{Size: 64 * 1024}
|
||||
json.NewDecoder(os.Stdin).Decode(out)
|
||||
fmt.Fprintln(os.Stderr, RandStringBytes(out.Size))
|
||||
fmt.Fprintln(os.Stderr, randStringBytes(out.Size))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user