packagemincssimport("bufio""bytes""io/ioutil""regexp""strings")funcRemoveCStyleComments(content[]byte)[]byte{// http://blog.ostermiller.org/find-commentccmt:=regexp.MustCompile(`/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/`)returnccmt.ReplaceAll(content,[]byte(""))}funcRemoveCppStyleComments(content[]byte)[]byte{cppcmt:=regexp.MustCompile(`//.*`)returncppcmt.ReplaceAll(content,[]byte(""))}funcconcatenateCSS(cssPathes[]string)[]byte{varcssAll[]bytefor_,cssPath:=rangecssPathes{println("concatenating "+cssPath+" ...")b,err:=ioutil.ReadFile(cssPath)iferr!=nil{panic(err)}cssAll=append(cssAll,b...)}returncssAll}funcMinifyCSS(cssPathes[]string)string{cssAll:=concatenateCSS(cssPathes)cssAllNoComments:=RemoveCppStyleComments(RemoveCStyleComments(cssAll))// read line by lineminifiedCss:=""scanner:=bufio.NewScanner(bytes.NewReader(cssAllNoComments))forscanner.Scan(){// all leading and trailing white space of each line are removedminifiedCss+=strings.TrimSpace(scanner.Text())}iferr:=scanner.Err();err!=nil{panic(err)}returnminifiedCss}