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 46 of 60 · Go

Building a HTTP/2 Server with TLS

Duration: 20 minutes

HTTP/2 + TLS

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

Go enables HTTP/2 automatically when serving over TLS.

cert, _ := tls.LoadX509KeyPair("server.crt", "server.key")
server := &http.Server{
    Addr:    ":443",
    Handler: mux,
    TLSConfig: &tls.Config{MinVersion: tls.VersionTLS12},
}
log.Fatal(server.ListenAndServeTLS("", "")) // cert/key already in TLSConfig

ALPN negotiation

The client and server negotiate HTTP/2 via ALPN during the TLS handshake.

Testing locally

$ mkcert -install
$ mkcert localhost

Then run the server with the generated localhost+2.pem and localhost+2-key.pem.

Info

HTTP/2 improves multiplexing and header compression – great for APIs.

Previous: Embedding a SQLite Database with `modernc.org/sqlite`Next: Deploying Go Services to Docker & Kubernetes