Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons

© 2026 BraveProgrammer. All rights reserved.

  1. Courses
  2. /
  3. Go Programming Bootcamp

Lesson 42 of 60 · Go

Embedding Files – `embed` Package (Go 1.16+)

Duration: 15 minutes

Compile‑time Assets

This lesson explains the main concept clearly with beginner-friendly examples and background so you can learn why the code works.

embed lets you embed static files directly into the binary.

import "embed"

//go:embed templates/*.html
var tmplFS embed.FS

func main() {
    files, _ := tmplFS.ReadDir("templates")
    for _, f := range files { fmt.Println(f.Name()) }
}

You can also embed a single file as a string:

//go:embed version.txt
var version string

Info

Embedding is perfect for CLI help messages, HTML templates, or SQL migrations.

Previous: Logging & Structured Tracing with OpenTelemetryNext: Performance Tuning – CPU, Memory, and GC