Compatible with the standard library

Add kcd to the standard library

By default Without doing anything KCD will be compatible with the golang http standard library.

However, some features will not works due to the fact that you are using a classic http handler:

  • Outputting struct

  • Returning error

  • Default status code

This may be useful in some cases:

  • if you have a large codebase and you want to progressively

    integrate kcd

  • if you have a complex code for instance WebSocket, SSE ...

Example:

package main

import (
	"github.com/alexisvisco/kcd"
	"net/http"
)

func main() {
	
	//                                                                    v   status code will be ignored	                                          
	http.HandleFunc("/example/", kcd.Handler(StandardHttpHandler, http.StatusOK))
	http.ListenAndServe(":8080", nil)
}

// StandardHttpHandler is a standard http handler and work with kcd.
// The default status code does not works since you are controlling
// the return via http.ResponseWriter.
//
// This may be useful in some cases:
// - if you have a large codebase and you want to progressively
//   integrate kcd
// - if you have a complex code for instance WebSocket, SSE ...
//
//                                                              v as you can see there is no error, and no output struct
func StandardHttpHandler(w http.ResponseWriter, r *http.Request) {
	w.Write([]byte("ok"))
}

Last updated