Gofmt is the usual tool for that
; echo 'mux.Handle("/add-referrer", handlers.LoggingHandler(os.Stderr,
auth.Trace(auth.IsAuthenticated(auth.IsReferrer(http.HandlerFunc(lh.AddReferrerHandler))))))'
> file
; cat file | gofmt
mux.Handle("/add-referrer", handlers.LoggingHandler(os.Stderr, auth.Trace(
auth.IsAuthenticated(auth.IsReferrer(http.HandlerFunc(lh.AddReferrerHandler
))))))
Usually piping to gofmt fixes syntax. But because gofmt doesn't split by
line length, it wont work. You can use a stream editor like sed to replace
'(' with '(\n' and then pipe to gofmt to fix that.
cat file | edit ",x,\\(,a,\n," | gofmt
mux.Handle(
"/add-referrer", handlers.LoggingHandler(
os.Stderr, auth.Trace(
auth.IsAuthenticated(
auth.IsReferrer(
http.HandlerFunc(
lh.AddReferrerHandler))))))
On Wednesday, September 6, 2017 at 9:10:43 PM UTC-7, Sankar wrote:
>
> Hi
>
> Are there any tools available for golang to split long functions so that
> they can fit in 80 columns (as long as possible) ?
>
> For example:
>
> ```
> mux.Handle("/login", handlers.LoggingHandler(os.Stderr,
> http.HandlerFunc(lh.LoginHandler)))
> mux.Handle("/add-referrer", handlers.LoggingHandler(os.Stderr,
> auth.Trace(auth.IsAuthenticated(auth.IsReferrer(http.HandlerFunc(lh.AddReferrerHandler))))))
> ```
>
> could become:
>
> ```
> mux.Handle(
> "/login",
> handlers.LoggingHandler(os.Stderr, http.HandlerFunc(lh.LoginHandler)))
> mux.Handle(
> "/add-referrer",
> handlers.LoggingHandler(
> os.Stderr,
> auth.Trace(
> auth.IsAuthenticated(
> auth.IsReferrer(http.HandlerFunc(lh.AddReferrerHandler)),
> ),
> ),
> ),
> )
> ```
> Google groups will make the indents in the above snippet display wrong,
> but you get the idea.
>
> Are there any tools (Similar to prettier for javascript) or techniques for
> getting this ?
>
> Thanks.
>
> Sankar
>
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.