package main import ( "fmt" "github.com/golangci/golines/shorten" ) func formatSource(source string, maxLen int) (output []byte, err error) { // Dependency panics must not escape the JS callback and terminate the WASM runtime. defer func() { if recovered := recover(); recovered != nil { output = nil err = fmt.Errorf("golines could not format this input (internal panic: %v). Ensure the input is a complete Go file, including a package declaration", recovered) } }() tabLen := 4 if maxLen < 80 { tabLen = 2 } return shorten.NewShortener(&shorten.Config{ MaxLen: maxLen, TabLen: tabLen, ShortenComments: true, ReformatTags: true, ChainSplitDots: true, }).Process([]byte(source)) }