Closed lyingcrow closed 3 years ago
@hjinbi The problem here is that comments would need to be added by adding a new crossplane.Directive
for the comment itself. For example:
pstr := func(s string) *string { return &s }
s := payload.Config[0].Parsed[0].Block
*s = append(*s,
crossplane.Directive{
Directive: "#",
Line: 13,
Comment: pstr(" above location"),
},
crossplane.Directive{
Directive: "location",
Line: 14,
Args: []string{"xxxxx"},
Block: &[]crossplane.Directive{
{
Directive: "#",
Line: 17,
Comment: pstr(" above xxx"),
},
{
Directive: "xxx",
Line: 18,
Args: []string{"xxxxxx"},
},
{
Directive: "#",
Line: 18,
Comment: pstr(" beside xxx"),
},
{
Directive: "#",
Line: 19,
Comment: pstr(" below xxx"),
},
},
},
crossplane.Directive{
Directive: "#",
Line: 15,
Comment: pstr(" below location"),
},
)
would add this nginx snippet to a config block:
# above location
location xxxxx {
# above xxx
xxx xxxxxx; # beside xxx
# below xxx
}
# below location
Let me know if that helps 🙂
thank you for your help !
how to use the Comment? The comment cannot be made to take effect, Here are some examples,