Skip to content

Commit

Permalink
#78 Add string to string encode for content
Browse files Browse the repository at this point in the history
  • Loading branch information
Reindert Vetter committed Nov 15, 2020
1 parent ece0716 commit 4ccdb15
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/http/middleware/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ import (
)

var Api = []inter.HttpMiddleware{
middleware.DefaultResponseEncoder{Encoder: outcome.Json},
middleware.DefaultResponseOutcome{Outcome: outcome.Json},
}
2 changes: 1 addition & 1 deletion app/http/middleware/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ import (
)

var Web = []inter.HttpMiddleware{
middleware.DefaultResponseEncoder{Encoder: outcome.Html},
middleware.DefaultResponseOutcome{Outcome: outcome.Html},
}
5 changes: 5 additions & 0 deletions app/providers/response_service_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,10 @@ func (c ResponseServiceProvider) Register(container inter.Container) inter.Conta
encoder.InterfaceToJson{},
})

container.Bind("outcome_content_encoders", []inter.Encoder{
// add your custom Content encoders here
encoder.StringToString{},
})

return container
}
10 changes: 9 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"lanvard/bootstrap"
"log"
net "net/http"
"strings"
"time"
)

Expand Down Expand Up @@ -67,10 +68,17 @@ func HandleKernel(response net.ResponseWriter, request *net.Request) {
kernel := app.Make((*inter.HttpKernel)(nil)).(http.Kernel)
appResponse := kernel.Handle(http.NewRequest(http.Options{App: app, Source: *request}))

// Add HTTP headers
for key, values := range appResponse.GetHeaders() {
response.Header().Add(key, strings.Join(values, "; "))
}

// Add HTTP status
response.WriteHeader(appResponse.GetStatus())

// Add HTTP body
_, err := response.Write([]byte(appResponse.GetBody()))
if err != nil {
panic(err)
}
// todo convert custom 'buffer' response headers to default go response
}
1 change: 0 additions & 1 deletion routes/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,4 @@ import (
*/
var Web = Group(
Get("/", controller.Homepage),
Post("/", controller.Homepage),
).Middleware(middleware.Web...)

0 comments on commit 4ccdb15

Please sign in to comment.