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
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

Embedding Files – `embed` P | Go Programming Bootcamp lesson | BraveProgrammer
  1. Courses
  2. /
  3. Go Programming Bootcamp

Lesson 42 of 60

·Go

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

15 minutes

Course progress70%

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  {
    files, _ := tmplFS.ReadDir()
     _, f :=  files { fmt.Println(f.Name()) }
}
main
()
"templates"
for
range

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.
Make it stickPractice what you've learned1 quiz · 3 practical tests · Optional activities from Go Programming BootcampBrowse activities
Previous lessonLogging & Structured Tracing with OpenTelemetryContinue to lesson 43Performance Tuning – CPU, Memory, and GCBack to Go Programming Bootcamp curriculum