Apply gofmt

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alex@openfaas.com>
This commit is contained in:
Alex Ellis (OpenFaaS Ltd) 2022-12-14 11:40:43 +00:00
parent 3bafff7e09
commit f3599f4699
5 changed files with 50 additions and 49 deletions

View File

@ -2,89 +2,89 @@
// //
// The traditional error handling idiom in Go is roughly akin to // The traditional error handling idiom in Go is roughly akin to
// //
// if err != nil { // if err != nil {
// return err // return err
// } // }
// //
// which when applied recursively up the call stack results in error reports // which when applied recursively up the call stack results in error reports
// without context or debugging information. The errors package allows // without context or debugging information. The errors package allows
// programmers to add context to the failure path in their code in a way // programmers to add context to the failure path in their code in a way
// that does not destroy the original value of the error. // that does not destroy the original value of the error.
// //
// Adding context to an error // # Adding context to an error
// //
// The errors.Wrap function returns a new error that adds context to the // The errors.Wrap function returns a new error that adds context to the
// original error by recording a stack trace at the point Wrap is called, // original error by recording a stack trace at the point Wrap is called,
// together with the supplied message. For example // together with the supplied message. For example
// //
// _, err := ioutil.ReadAll(r) // _, err := ioutil.ReadAll(r)
// if err != nil { // if err != nil {
// return errors.Wrap(err, "read failed") // return errors.Wrap(err, "read failed")
// } // }
// //
// If additional control is required, the errors.WithStack and // If additional control is required, the errors.WithStack and
// errors.WithMessage functions destructure errors.Wrap into its component // errors.WithMessage functions destructure errors.Wrap into its component
// operations: annotating an error with a stack trace and with a message, // operations: annotating an error with a stack trace and with a message,
// respectively. // respectively.
// //
// Retrieving the cause of an error // # Retrieving the cause of an error
// //
// Using errors.Wrap constructs a stack of errors, adding context to the // Using errors.Wrap constructs a stack of errors, adding context to the
// preceding error. Depending on the nature of the error it may be necessary // preceding error. Depending on the nature of the error it may be necessary
// to reverse the operation of errors.Wrap to retrieve the original error // to reverse the operation of errors.Wrap to retrieve the original error
// for inspection. Any error value which implements this interface // for inspection. Any error value which implements this interface
// //
// type causer interface { // type causer interface {
// Cause() error // Cause() error
// } // }
// //
// can be inspected by errors.Cause. errors.Cause will recursively retrieve // can be inspected by errors.Cause. errors.Cause will recursively retrieve
// the topmost error that does not implement causer, which is assumed to be // the topmost error that does not implement causer, which is assumed to be
// the original cause. For example: // the original cause. For example:
// //
// switch err := errors.Cause(err).(type) { // switch err := errors.Cause(err).(type) {
// case *MyError: // case *MyError:
// // handle specifically // // handle specifically
// default: // default:
// // unknown error // // unknown error
// } // }
// //
// Although the causer interface is not exported by this package, it is // Although the causer interface is not exported by this package, it is
// considered a part of its stable public interface. // considered a part of its stable public interface.
// //
// Formatted printing of errors // # Formatted printing of errors
// //
// All error values returned from this package implement fmt.Formatter and can // All error values returned from this package implement fmt.Formatter and can
// be formatted by the fmt package. The following verbs are supported: // be formatted by the fmt package. The following verbs are supported:
// //
// %s print the error. If the error has a Cause it will be // %s print the error. If the error has a Cause it will be
// printed recursively. // printed recursively.
// %v see %s // %v see %s
// %+v extended format. Each Frame of the error's StackTrace will // %+v extended format. Each Frame of the error's StackTrace will
// be printed in detail. // be printed in detail.
// //
// Retrieving the stack trace of an error or wrapper // # Retrieving the stack trace of an error or wrapper
// //
// New, Errorf, Wrap, and Wrapf record a stack trace at the point they are // New, Errorf, Wrap, and Wrapf record a stack trace at the point they are
// invoked. This information can be retrieved with the following interface: // invoked. This information can be retrieved with the following interface:
// //
// type stackTracer interface { // type stackTracer interface {
// StackTrace() errors.StackTrace // StackTrace() errors.StackTrace
// } // }
// //
// The returned errors.StackTrace type is defined as // The returned errors.StackTrace type is defined as
// //
// type StackTrace []Frame // type StackTrace []Frame
// //
// The Frame type represents a call site in the stack trace. Frame supports // The Frame type represents a call site in the stack trace. Frame supports
// the fmt.Formatter interface that can be used for printing information about // the fmt.Formatter interface that can be used for printing information about
// the stack trace of this error. For example: // the stack trace of this error. For example:
// //
// if err, ok := err.(stackTracer); ok { // if err, ok := err.(stackTracer); ok {
// for _, f := range err.StackTrace() { // for _, f := range err.StackTrace() {
// fmt.Printf("%+s:%d\n", f, f) // fmt.Printf("%+s:%d\n", f, f)
// } // }
// } // }
// //
// Although the stackTracer interface is not exported by this package, it is // Although the stackTracer interface is not exported by this package, it is
// considered a part of its stable public interface. // considered a part of its stable public interface.
@ -265,9 +265,9 @@ func (w *withMessage) Format(s fmt.State, verb rune) {
// An error value has a cause if it implements the following // An error value has a cause if it implements the following
// interface: // interface:
// //
// type causer interface { // type causer interface {
// Cause() error // Cause() error
// } // }
// //
// If the error does not implement Cause, the original error will // If the error does not implement Cause, the original error will
// be returned. If the error is nil, nil will be returned without further // be returned. If the error is nil, nil will be returned without further

View File

@ -1,3 +1,4 @@
//go:build go1.13
// +build go1.13 // +build go1.13
package errors package errors

View File

@ -51,16 +51,16 @@ func (f Frame) name() string {
// Format formats the frame according to the fmt.Formatter interface. // Format formats the frame according to the fmt.Formatter interface.
// //
// %s source file // %s source file
// %d source line // %d source line
// %n function name // %n function name
// %v equivalent to %s:%d // %v equivalent to %s:%d
// //
// Format accepts flags that alter the printing of some verbs, as follows: // Format accepts flags that alter the printing of some verbs, as follows:
// //
// %+s function name and path of source file relative to the compile time // %+s function name and path of source file relative to the compile time
// GOPATH separated by \n\t (<funcname>\n\t<path>) // GOPATH separated by \n\t (<funcname>\n\t<path>)
// %+v equivalent to %+s:%d // %+v equivalent to %+s:%d
func (f Frame) Format(s fmt.State, verb rune) { func (f Frame) Format(s fmt.State, verb rune) {
switch verb { switch verb {
case 's': case 's':
@ -98,12 +98,12 @@ type StackTrace []Frame
// Format formats the stack of Frames according to the fmt.Formatter interface. // Format formats the stack of Frames according to the fmt.Formatter interface.
// //
// %s lists source files for each Frame in the stack // %s lists source files for each Frame in the stack
// %v lists the source file and line number for each Frame in the stack // %v lists the source file and line number for each Frame in the stack
// //
// Format accepts flags that alter the printing of some verbs, as follows: // Format accepts flags that alter the printing of some verbs, as follows:
// //
// %+v Prints filename, function, and line number for each Frame in the stack. // %+v Prints filename, function, and line number for each Frame in the stack.
func (st StackTrace) Format(s fmt.State, verb rune) { func (st StackTrace) Format(s fmt.State, verb rune) {
switch verb { switch verb {
case 'v': case 'v':

View File

@ -5,7 +5,7 @@ package handlers
import "net/http" import "net/http"
//HealthzHandler healthz hanlder for mertics server // HealthzHandler healthz hanlder for mertics server
func HealthzHandler(w http.ResponseWriter, r *http.Request) { func HealthzHandler(w http.ResponseWriter, r *http.Request) {
switch r.Method { switch r.Method {

View File

@ -278,7 +278,7 @@ func main() {
log.Fatal(s.ListenAndServe()) log.Fatal(s.ListenAndServe())
} }
//runMetricsServer Listen on a separate HTTP port for Prometheus metrics to keep this accessible from // runMetricsServer Listen on a separate HTTP port for Prometheus metrics to keep this accessible from
// the internal network only. // the internal network only.
func runMetricsServer() { func runMetricsServer() {
metricsHandler := metrics.PrometheusHandler() metricsHandler := metrics.PrometheusHandler()