utils.go 717 B

12345678910111213141516171819202122232425262728293031323334
  1. package main
  2. import (
  3. "fmt"
  4. "strings"
  5. "golang.org/x/tools/imports"
  6. )
  7. // GoImport Use golang.org/x/tools/imports auto import pkg
  8. func GoImport(file string, bytes []byte) (res []byte, err error) {
  9. options := &imports.Options{
  10. TabWidth: 8,
  11. TabIndent: true,
  12. Comments: true,
  13. Fragment: true,
  14. }
  15. if res, err = imports.Process(file, bytes, options); err != nil {
  16. fmt.Printf("GoImport(%s) error(%v)", file, err)
  17. res = bytes
  18. return
  19. }
  20. return
  21. }
  22. // IsService checkout the file belongs to service or not
  23. func IsService(pName string) bool {
  24. return pName == "service"
  25. }
  26. //ConvertHump convert words to hump style
  27. func ConvertHump(words string) string {
  28. return strings.ToUpper(words[0:1]) + words[1:]
  29. }