til

Today I Learned: collection of notes, tips and tricks and stuff I learn from day to day working with computers and technology as an open source contributor and product manager

View project on GitHub

Multiline Strings

Multiline strings in Go have to be quoted using: `

The content of the multiline string is handled as-is, so it can contain anything, is regarded as a raw string literal.

One crazy example could be:

package main

import (
    "fmt"
    "strings"
)

const startupMessage = `                                                                                
                                                   �                            
                                                                                
                                                                                
                                               ��������                         
                                              �������          �                
  ��        �� ��   ���  ��                  �������          � ����            
  �          ����       ����          ����          �         �  ���            
  �      �    ��    ���               ����                     �����            
                     �         �����������            �           ���������     
                                            �����   ����        ����������      
                                              �      �������                    
             � �  �                                 �����������       �         
                  �  �        ��  ��  �         � ����������������   ��         
                           ��� �     �� �           �����������������           
`

func main() {

    lines := strings.Split(startupMessage, "\n")
    fmt.Println()
    for _, line := range lines {
        fmt.Println(line)
    }
}

String literal example lifted from: Digital Oceans Go sample for their app platform.

Resources and References

  1. Yourbasic.org
  2. Go Documentation on String Literal
  3. DigitalOcean Go Sample