Simple hosts file management in Go (golang).
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

37 lines
629 B

  1. package goodhosts
  2. import (
  3. "fmt"
  4. "strings"
  5. )
  6. func itemInSlice(item string, list []string) bool {
  7. for _, i := range list {
  8. if i == item {
  9. return true
  10. }
  11. }
  12. return false
  13. }
  14. func buildRawLine(ip string, host, comment string) string {
  15. output := ip
  16. output = fmt.Sprintf("%s %s", output, host)
  17. if len(comment) > 0 {
  18. comment = "#" + comment
  19. output = fmt.Sprintf("%s %s", output, comment)
  20. }
  21. return output
  22. }
  23. // IsComment Return ```true``` if the line is a comment.
  24. func IsComment(line string) bool {
  25. trimLine := strings.TrimSpace(line)
  26. isComment := strings.HasPrefix(trimLine, commentChar)
  27. return isComment
  28. }