interface.go 917 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * @Descripttion:敏感词
  3. * @version:
  4. * @Author: Neo,Huang
  5. * @Date: 2021-04-17 11:04:16
  6. * @LastEditors: Neo,Huang
  7. * @LastEditTime: 2021-04-20 09:52:10
  8. */
  9. package sensitive
  10. import (
  11. "encoding/json"
  12. "net/http"
  13. )
  14. // 初始化
  15. func Init() {
  16. InitDFA()
  17. }
  18. // 敏感词检查
  19. // 方法:get
  20. // 参数:
  21. // word:检查字符串
  22. // 返回
  23. // true/false
  24. func HttpCheckWord(w http.ResponseWriter, r *http.Request) {
  25. req := r.URL.Query()
  26. word := req.Get("word")
  27. cw := CheckSensitive(word, sensitiveWord)
  28. // 发送成功
  29. w.Write([]byte(cw))
  30. }
  31. // 敏感词检查
  32. // 方法:get
  33. // 参数:
  34. // word:检查字符串
  35. // 返回
  36. // true/false
  37. func HttpChangeWord(w http.ResponseWriter, r *http.Request) {
  38. req := r.URL.Query()
  39. word := req.Get("word")
  40. ret := make(map[string]string)
  41. ret["word"] = ChangeSensitiveWords(word, sensitiveWord)
  42. pack, _ := json.Marshal(ret)
  43. // 发送成功
  44. w.Write(pack)
  45. }