action_mysql.go 943 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package actions
  2. import (
  3. "fmt"
  4. utils "golang-fave/engine/wrapper/utils"
  5. )
  6. func action_mysql(e *Action) {
  7. pf_host := e.R.FormValue("host")
  8. pf_name := e.R.FormValue("name")
  9. pf_user := e.R.FormValue("user")
  10. pf_password := e.R.FormValue("password")
  11. if pf_host == "" {
  12. e.write(fmt.Sprintf(`ModalShowMsg('Error', 'Please specify host for mysql connection');`))
  13. return
  14. }
  15. if pf_name == "" {
  16. e.write(fmt.Sprintf(`ModalShowMsg('Error', 'Please specify mysql database name');`))
  17. return
  18. }
  19. if pf_user == "" {
  20. e.write(fmt.Sprintf(`ModalShowMsg('Error', 'Please specify mysql user');`))
  21. return
  22. }
  23. // Try connect to mysql
  24. // Try to install all tables
  25. // Save mysql config file
  26. err := utils.MySqlConfigWrite(e.VHostHome, pf_host, pf_name, pf_user, pf_password)
  27. if err != nil {
  28. e.write(fmt.Sprintf(`ModalShowMsg('Error', '%s');`, err))
  29. }
  30. // Reload current page
  31. e.write(fmt.Sprintf(`window.location.reload(false);`))
  32. }