github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/talks/2014/readability/resthandler.go (about)

     1  // +build OMIT
     2  
     3  package resthandler // OMIT
     4  
     5  func (h *RESTHandler) finishReq(op *Operation, req *http.Request, w http.ResponseWriter) {
     6  	result, complete := op.StatusOrResult()
     7  	obj := result.Object
     8  	if complete {
     9  		status := http.StatusOK // HL
    10  		if result.Created {
    11  			status = http.StatusCreated // HL
    12  		}
    13  		switch stat := obj.(type) {
    14  		case *api.Status:
    15  			if stat.Code != 0 {
    16  				status = stat.Code // HL
    17  			}
    18  		}
    19  		writeJSON(status, h.codec, obj, w) // HL
    20  	} else {
    21  		writeJSON(http.StatusAccepted, h.codec, obj, w) // HL
    22  	}
    23  }