Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to split a long Go template function across multiple lines?

I have a very long printf call in a Go template. Example:

{{ printf "mongodb://%s:%s@%s/%s?authSource=admin&replicaSet=%s&readPreference=nearest&w=majority" .Values.rocketchat.mongo.username .Values.rocketchat.mongo.password .Values.rocketchat.mongo.database .Values.mongodb-replicaset.replicaSetName | b64enc | quote }}

How can I split this across multiple lines (like below)?

{{ printf "mongodb://%s:%s@%s/%s?authSource=admin&replicaSet=%s&readPreference=nearest&w=majority"
    .Values.rocketchat.mongo.username
    .Values.rocketchat.mongo.password
    .Values.rocketchat.mongo.database
    .Values.mongodb-replicaset.replicaSetName
    | b64enc | quote }}
like image 968
allsap Avatar asked Apr 13 '18 12:04

allsap


1 Answers

This cannot be done. From the text/template documentation:

Except for raw strings, actions may not span newlines, although comments can.

like image 129
Tim Cooper Avatar answered Dec 08 '22 18:12

Tim Cooper