package handler import ( "io" "os" "path/filepath" "fmt" "hamlogger/internal/router" ) type HelloParams struct{} type HelloResult struct{} func (hand *Handler) GetHello(ctx *router.Context) { var err error res := &HelloResult{} hand.SendResult(ctx, res, err) } func (hand *Handler) GetIndex(ctx *router.Context) { filename := "index.html" filename = filepath.Join(hand.sharedir, filename) file, err := os.Open(filename) if err != nil { hand.log.Errorf("cannot open file %s: %v", filename, err) return } stat, _ := file.Stat() ctx.Writer.Header().Set("Content-Type", "text/html; charset=utf-8") ctx.Writer.Header().Set("Content-Length", fmt.Sprintf("%d", stat.Size())) defer file.Close() io.Copy(ctx.Writer, file) //ctx.Writer.Write([]byte(payload)) } /* func (hand *Handler) SendHTML(ctx *router.Context, filename string) { ctx.Writer.Header().Set("Content-Type", "text/html; charset=utf-8") file, _ := os.Open(filepath.Join(hand.sharedir, filename)) defer file.Close() io.Copy(ctx.Writer, file) //ctx.Writer.Write([]byte(payload)) } */