Hacker News new | ask | show | jobs
by minieggs 1951 days ago
The go:embed directive and embed.FS interface are great, as expected. If you're developing an AGPL or similarily licensed application it's incredibly easy to distribute source code with the application.

//go:embed main.go go.mod go.sum LICENSE README makefile static/*

var sourceCode embed.FS

// ...

func main() {

    // ...

    http.Handle("/source/", http.StripPrefix("/source/", http.FileServer(http.FS(sourceCode))))

    // ...

}
1 comments

Also quines become incredibly easy:

  package main
  
  import (
      _ "embed"
      "fmt"
  )
  
  //go:embed quine.go
  var src string
  
  func main() {
      fmt.Print(src)
  }