wrap-expression

The wrap-expression advice replaces the matched node with the one produced by the provided code template. Care must be taken to not change the type of the expression, as this could result in breaking surrounding code.

It is commonly used to wrap values in immediately-invoked function expressions (IIFE).

Examples

wrap-expression:
  imports:
    mongotrace: gopkg.in/DataDog/dd-trace-go.v1/contrib/go.mongodb.org/mongo-driver/mongo
    options: go.mongodb.org/mongo-driver/mongo/options
  template: "{{ . }}.SetMonitor(mongotrace.NewMonitor())"
wrap-expression:
  imports:
    chi: github.com/go-chi/chi
    chitrace: gopkg.in/DataDog/dd-trace-go.v1/contrib/go-chi/chi
  template: |-
    func() *chi.Mux {
    	mux := {{ . }}
    	mux.Use(chitrace.Middleware())
    	return mux
    }()