packageminhtmlimport("bufio""bytes""regexp""strings")funcRemoveHTMLComments(content[]byte)[]byte{// https://www.google.com/search?q=regex+html+comments// http://stackoverflow.com/a/1084759htmlcmt:=regexp.MustCompile(`<!--[^>]*-->`)returnhtmlcmt.ReplaceAll(content,[]byte(""))}funcMinifyHTML(html[]byte)string{// read line by lineminifiedHTML:=""scanner:=bufio.NewScanner(bytes.NewReader(RemoveHTMLComments(html)))forscanner.Scan(){// all leading and trailing white space of each line are removedlineTrimmed:=strings.TrimSpace(scanner.Text())minifiedHTML+=lineTrimmediflen(lineTrimmed)>0{// in case of following trimmed line:// <div id="foo"minifiedHTML+=" "}}iferr:=scanner.Err();err!=nil{panic(err)}returnminifiedHTML}