api_w_random.go 615 B

12345678910111213141516171819202122232425262728293031
  1. package route
  2. import (
  3. "database/sql"
  4. "encoding/json"
  5. "log"
  6. "opennamu/route/tool"
  7. )
  8. func Api_w_random(call_arg []string) string {
  9. db := tool.DB_connect()
  10. defer db.Close()
  11. var title string
  12. err := db.QueryRow(tool.DB_change("select title from data where title not like 'user:%' and title not like 'category:%' and title not like 'file:%' order by random() limit 1")).Scan(&title)
  13. if err != nil {
  14. if err == sql.ErrNoRows {
  15. title = ""
  16. } else {
  17. log.Fatal(err)
  18. }
  19. }
  20. new_data := map[string]string{}
  21. new_data["data"] = title
  22. json_data, _ := json.Marshal(new_data)
  23. return string(json_data)
  24. }