mirror of
				https://github.com/AlexxIT/go2rtc.git
				synced 2025-10-31 19:53:02 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			27 lines
		
	
	
		
			500 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			27 lines
		
	
	
		
			500 B
		
	
	
	
		
			Go
		
	
	
	
	
	
| package api
 | |
| 
 | |
| import (
 | |
| 	"github.com/AlexxIT/go2rtc/www"
 | |
| 	"net/http"
 | |
| )
 | |
| 
 | |
| func initStatic(staticDir string) {
 | |
| 	var root http.FileSystem
 | |
| 	if staticDir != "" {
 | |
| 		log.Info().Str("dir", staticDir).Msg("[api] serve static")
 | |
| 		root = http.Dir(staticDir)
 | |
| 	} else {
 | |
| 		root = http.FS(www.Static)
 | |
| 	}
 | |
| 
 | |
| 	base := len(basePath)
 | |
| 	fileServer := http.FileServer(root)
 | |
| 
 | |
| 	HandleFunc("", func(w http.ResponseWriter, r *http.Request) {
 | |
| 		if base > 0 {
 | |
| 			r.URL.Path = r.URL.Path[base:]
 | |
| 		}
 | |
| 		fileServer.ServeHTTP(w, r)
 | |
| 	})
 | |
| }
 | 
