Categorygithub.com/go-zoox/api-cmr
modulepackage
1.0.1
Repository: https://github.com/go-zoox/api-cmr.git
Documentation: pkg.go.dev

# README

API CMR

Use API CMR (Code + Message + Result) Specification, like jSend.

PkgGoDev Build Status Go Report Card Coverage Status GitHub issues Release

Installation

To install the package, run:

go get github.com/go-zoox/api-cmr

Getting Started

package main

import (
  "github.com/go-zoox/api-cmr"
)

func main(t *testing.T) {
	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		w.Write(cmr.Success("Hello World!"))
		// or
		cmr.WriteSuccess(w, "Hello World!")
	})

	http.ListenAndServe(":8080", nil)
}

Inspired By

  • omniti-labs/jsend - JSend is a specification for a simple, no-frills, JSON based format for application-level communication

License

GoZoox is released under the MIT License.

# Functions

Fail return a fail body, bad request causes calculation error.
Register registers a pair of code and message.
Success return a succes body.
WriteFail writes a fail response to the response writer.
WriteSuccess writes a success response to the response writer.

# Variables

Version is the current version of the package.

# Structs

Body is the response body.