Richard Bucker

Example SFlow

Posted at — Jul 22, 2015

Previously I mentioned a project, execon, which I’m planning to rename SFlow, however, one of the missing pieces for the casual reader is what’s it all about?BEFOREfunc DeleteMerchInfoHandlerOld(w http.ResponseWriter, r *http.Request) (int, error) {        if r.Method != “DELETE” {                return http.StatusMethodNotAllowed, errInvalidMethod        }        payloadValue := r.FormValue(“payload”)        if payloadValue == " {                return http.StatusBadRequest, errExpectedEmpty        }        request := mdata.RemoteRequest{}        if err := json.Unmarshal([]byte(payloadValue), &request); err != nil {                return http.StatusBadRequest, err        }        merchInfo := mdata.MerchInfo{}        if err := transcode.Transform(&merchInfo, request); err != nil {                return http.StatusBadRequest, err        }        if found := merchinfo.Dirty(merchInfo); found == false {                return http.StatusBadRequest, errMerchNotFound        }        return http.StatusOK, nil}AFTERtype DeleteMerchInfo struct {        Init                 execon.ExeConTask params:"FIRST"        MustDeleteMethod     execon.ExeConTask        PayloadNotEmpty      execon.ExeConTask        ParsePayload         execon.ExeConTask        CastPayloadMerchInfo execon.ExeConTask        SetMerchInfoDirty    execon.ExeConTask switch:"{\"HttpError\":\"Finish\"}"        Finish               execon.ExeConTask        Error                execon.ExeConTask        HttpError            execon.ExeConTask        FuncLib}I don’t want to spoon feed the reader with all of the gory details but there were a bunch of things that I learned in the process of converting this workflow.The AFTER is so much easier to readThe AFTER is so much easier to extendThe AFTER takes advantage of shared code libraryThe AFTER can actually be assembled, composed or generated from textural fragments or gistsThe BEFORE did not have enough documentationThe BEFORE did not consider some other optionsThe BEFORE required the user to interpret the summary descriptionAs a side effect there were a number of testcases that I missed. There were a few test cases that were broken and needed fixing. And in one case I had missed a use-case that needed to be tested. And while I was working in this particular “switch” (above) I found that I missed a case in the framework implementation. (for another day; but no one is perfect).