github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/pkg/depends/kit/httptransport/transport_util.go (about)

     1  package httptransport
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  
     7  	"github.com/fatih/color"
     8  	"github.com/pkg/errors"
     9  )
    10  
    11  func tryCatch(fn func()) (err error) {
    12  	defer func() {
    13  		if e := recover(); e != nil {
    14  			err = errors.Errorf("%+v", e)
    15  		}
    16  	}()
    17  
    18  	fn()
    19  	return nil
    20  }
    21  
    22  func outputln(format string, args ...interface{}) {
    23  	fmt.Printf(`[Kit] `+format+"\n", args...)
    24  }
    25  
    26  func methodColor(method string) func(f string, args ...interface{}) string {
    27  	switch method {
    28  	case http.MethodGet:
    29  		return color.BlueString
    30  	case http.MethodPost:
    31  		return color.GreenString
    32  	case http.MethodPut:
    33  		return color.YellowString
    34  	case http.MethodDelete:
    35  		return color.RedString
    36  	default:
    37  		return color.WhiteString
    38  	}
    39  }