module_index_act_cypress.go 900 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package modules
  2. import (
  3. "database/sql"
  4. _ "github.com/go-sql-driver/mysql"
  5. "os"
  6. "golang-fave/consts"
  7. "golang-fave/engine/wrapper"
  8. )
  9. func (this *Modules) RegisterAction_IndexCypressReset() *Action {
  10. return this.newAction(AInfo{
  11. WantDB: false,
  12. Mount: "index-cypress-reset",
  13. }, func(wrap *wrapper.Wrapper) {
  14. if !consts.ParamDebug {
  15. wrap.Write(`Access denied`)
  16. return
  17. }
  18. db, err := sql.Open("mysql", "root:root@tcp(localhost:3306)/fave")
  19. if err != nil {
  20. wrap.Write(err.Error())
  21. return
  22. }
  23. defer db.Close()
  24. err = db.Ping()
  25. if err != nil {
  26. wrap.Write(err.Error())
  27. return
  28. }
  29. os.Remove(wrap.DConfig + string(os.PathSeparator) + ".installed")
  30. os.Remove(wrap.DConfig + string(os.PathSeparator) + "mysql.json")
  31. _, _ = db.Exec(
  32. `DROP TABLE
  33. blog_cats,
  34. blog_cat_post_rel,
  35. blog_posts,
  36. pages,
  37. users
  38. ;`,
  39. )
  40. wrap.Write(`OK`)
  41. })
  42. }