27 lines
		
	
	
		
			525 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			27 lines
		
	
	
		
			525 B
		
	
	
	
		
			Go
		
	
	
	
	
	
package frontend
 | 
						|
 | 
						|
import (
 | 
						|
	"log"
 | 
						|
	"net/http"
 | 
						|
	"path/filepath"
 | 
						|
 | 
						|
	b "streifling.com/jason/cpolis/cmd/backend"
 | 
						|
)
 | 
						|
 | 
						|
func ServeImage(c *b.Config, s *b.CookieStore) http.HandlerFunc {
 | 
						|
	return func(w http.ResponseWriter, r *http.Request) {
 | 
						|
		if _, err := getSession(w, r, c, s); err != nil {
 | 
						|
			return
 | 
						|
		}
 | 
						|
 | 
						|
		absFilepath, err := filepath.Abs(c.PicsDir)
 | 
						|
		if err != nil {
 | 
						|
			log.Println(err)
 | 
						|
			http.Error(w, err.Error(), http.StatusInternalServerError)
 | 
						|
			return
 | 
						|
		}
 | 
						|
 | 
						|
		http.ServeFile(w, r, absFilepath+"/"+r.PathValue("pic"))
 | 
						|
	}
 | 
						|
}
 |