Documentation ¶
Overview ¶
The library for cloud-init User Data. This is licensed under the MIT License.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Header ¶
type Header struct {
textproto.MIMEHeader
}
type MediaType ¶
type MediaType string
const ( MediaTypeCloudBoothook MediaType = "text/cloud-boothook" MediaTypeCloudConfig MediaType = "text/cloud-config" MediaTypeCloudConfigArchive MediaType = "text/cloud-config-archive" MediaTypeCloudConfigJsonp MediaType = "text/cloud-config-jsonp" MediaTypeJinja2 MediaType = "text/jinja2" MediaTypePartHandler MediaType = "text/part-handler" MediaTypeXIncludeOnceUrl MediaType = "text/x-include-once-url" MediaTypeXIncludeUrl MediaType = "text/x-include-url" MediaTypeXShellscript MediaType = "text/x-shellscript" MediaTypeXShellscriptPerBoot MediaType = "text/x-shellscript-per-boot" MediaTypeXShellscriptPerInstance MediaType = "text/x-shellscript-per-instance" MediaTypeXShellscriptPerOnce MediaType = "text/x-shellscript-per-once" )
type Multipart ¶
func NewMultipart ¶
func NewMultipart() *Multipart
func (*Multipart) Render ¶
Example ¶
package main import ( "bytes" "fmt" "strings" userdata "github.com/Aton-Kish/gouserdata" ) func main() { d := userdata.NewMultipart() cfg := []byte(`#cloud-config timezone: Europe/London`) d.AddPart(userdata.MediaTypeCloudConfig, cfg) scr := []byte(`#!/bin/bash echo 'Hello World'`) d.AddPart(userdata.MediaTypeXShellscript, scr) buf := new(bytes.Buffer) d.Render(buf) output := buf.String() output = strings.ReplaceAll(output, "\r\n", "\n") // for testing fmt.Println(output) }
Output: Content-Type: multipart/mixed; boundary="+Go+User+Data+Boundary==" Mime-Version: 1.0 --+Go+User+Data+Boundary== Content-Transfer-Encoding: 7bit Content-Type: text/cloud-config; charset=us-ascii #cloud-config timezone: Europe/London --+Go+User+Data+Boundary== Content-Transfer-Encoding: 7bit Content-Type: text/x-shellscript; charset=us-ascii #!/bin/bash echo 'Hello World' --+Go+User+Data+Boundary==--
Example (IncludesUtf8) ¶
package main import ( "bytes" "fmt" "strings" userdata "github.com/Aton-Kish/gouserdata" ) func main() { d := userdata.NewMultipart() cfg := []byte(`#cloud-config timezone: Asia/Tokyo`) d.AddPart(userdata.MediaTypeCloudConfig, cfg) scr := []byte(`#!/bin/bash echo 'こんにちは世界'`) d.AddPart(userdata.MediaTypeXShellscript, scr) buf := new(bytes.Buffer) d.Render(buf) output := buf.String() output = strings.ReplaceAll(output, "\r\n", "\n") // for testing fmt.Println(output) }
Output: Content-Type: multipart/mixed; boundary="+Go+User+Data+Boundary==" Mime-Version: 1.0 --+Go+User+Data+Boundary== Content-Transfer-Encoding: 7bit Content-Type: text/cloud-config; charset=us-ascii #cloud-config timezone: Asia/Tokyo --+Go+User+Data+Boundary== Content-Transfer-Encoding: base64 Content-Type: text/x-shellscript; charset=utf-8 IyEvYmluL2Jhc2gKZWNobyAn44GT44KT44Gr44Gh44Gv5LiW55WMJw== --+Go+User+Data+Boundary==--
func (*Multipart) SetBoundary ¶
Example ¶
package main import ( "bytes" "fmt" "log" "strings" userdata "github.com/Aton-Kish/gouserdata" ) func main() { d := userdata.NewMultipart() if err := d.SetBoundary("+Custom+User+Data+Boundary+"); err != nil { log.Fatal(err) } scr := []byte(`#!/bin/bash echo 'Hello World'`) d.AddPart(userdata.MediaTypeXShellscript, scr) buf := new(bytes.Buffer) d.Render(buf) output := buf.String() output = strings.ReplaceAll(output, "\r\n", "\n") // for testing fmt.Println(output) }
Output: Content-Type: multipart/mixed; boundary=+Custom+User+Data+Boundary+ Mime-Version: 1.0 --+Custom+User+Data+Boundary+ Content-Transfer-Encoding: 7bit Content-Type: text/x-shellscript; charset=us-ascii #!/bin/bash echo 'Hello World' --+Custom+User+Data+Boundary+--
Click to show internal directories.
Click to hide internal directories.