HttpStaticFiles
Alex Tan edited this page Jul 10, 2016
·
5 revisions
Serving Static Files with HTTP
The HTTP package provides good support for efficiently serving static files.
This is a complete Go webserver serving static files:
package main
import "net/http"
func main() {
panic(http.ListenAndServe(":8080", http.FileServer(http.Dir("/usr/share/doc"))))
}That example is intentionally short to make a point. Using panic() to deal with an error is probably too aggressive & would produce too much output.
See net/http documentation and in particular the FileServer example for a more typical example.
Pages 167
- Home
- Articles
- AssemblyPolicy
- AVX512
- Benchmarks
- Blogs
- Books
- BoundingResourceUse
- cgo
- ChromeOS
- CodeReview
- CodeReviewComments
- CodeTools
- Comments
- CommitMessage
- CommonMistakes
- CompilerOptimizations
- Conferences
- Configuring GoLand for WebAssembly
- Contributing to gopls
- CoreDumpDebugging
- Courses
- CreatingSubRepository
- CSSStyleGuide
- CustomPprofProfiles
- Darwin
- DashboardBuilders
- Deprecated
- DesignDocuments
- DevExp
- Diagnostics
- DragonFly BSD
- Errors
- ErrorValueFAQ
- ExperienceReports
- FileTreeDocumentation
- FreeBSD
- FromXToGo
- Frozen
- Gardening
- GccgoCrossCompilation
- GcToolchainTricks
- GerritAccess
- GerritBot
- GithubAccess
- GitHubCodeLayout
- Go 1.10 Release Party
- Go 1.6 release party
- Go 1.8 Release Party
- Go Community Slides
- Go Release Cycle
- Go1point1Gotchas
- Go2
- Go2ErrorHandlingFeedback
- Go2ErrorValuesFeedback
- Go2GenericsFeedback
- GoArm
- GoForCPPProgrammers
- GoGenerateTools
- GoGetProxyConfig
- GoGetTools
- golang tools
- GoMips
- Gomote
- GOPATH
- Gopher
- gopherbot
- gopls
- gopls integrator FAQ
- GoStrings
- GoTalks
- GoUserGroups
- GoUsers
- GoVsGenerics
- HandlingIssues
- Hashing
- heapdump13
- heapdump14
- heapdump15
- heapdump15 through heapdump17
- HostedContinuousIntegration
- How to ask for help
- HowToAsk
- HttpFetch
- HttpStaticFiles
- IDEsAndTextEditorPlugins
- InstallFromSource
- InstallTroubleshooting
- InterfaceSlice
- InvalidFlag
- Iota
- IssueLabels
- Learn
- LearnConcurrency
- LearnErrorHandling
- LearnServerProgramming
- LearnTesting
- Linux
- LinuxKernelSignalVectorBug
- Livestreams
- LockOSThread
- MethodSets
- MinimumRequirements
- MinorReleases
- Mobile
- Modules
- MultipleGoRoots
- MutexOrChannel
- NativeClient
- NetBSD
- NewSpeakers
- NoMeToo
- NonEnglish
- NoPlusOne
- OlderVersions
- OpenBSD
- PackageManagementTools
- PackagePublishing
- PanicAndRecover
- PerfDashboard
- Performance
- Plan9
- Podcasts
- PortingPolicy
- PriorDiscussion
- Projects
- Proposals
- ProviderIntegration
- Questions
- RaceDetector
- Range
- RateLimiting
- Rationales
- ResearchPapers
- Resolving Problems From Modified Module Path
- Screencasts
- SendingMail
- SettingGOPATH
- SignalHandling
- SimultaneousAssignment
- SliceTricks
- SlowBots
- Solaris
- Spectre
- Spelling
- SQLDrivers
- SQLInterface
- Style
- SuccessStories
- Switch
- TableDrivenTests
- TargetSpecific
- TestComments
- Timeouts
- Training
- Ubuntu
- vgo
- WebAccessibilityResourcesAndTips
- WebAssembly
- Well known struct tags
- WhyGo
- Windows
- windows scoop install go cli
- WindowsBuild
- WindowsCrossCompiling
- WindowsDLLs
- X Repositories

