feat: refactor system info retrieval and enhance logo output

- Replaced viper calls with utility functions in GetSystemInfo to improve code clarity and maintainability.
- Added a new system.go file with utility functions for retrieving system version and edition information.
- Enhanced PrintLogoWithWelcomeInfo to include detailed system information, improving user experience during server startup.
- Updated output formatting for better readability and consistency in welcome messages.
This commit is contained in:
Marvin Zhang
2024-12-29 19:01:23 +08:00
parent a8bf1156c4
commit 54800974eb
4 changed files with 47 additions and 11 deletions

View File

@@ -2,14 +2,14 @@ package controllers
import (
"github.com/crawlab-team/crawlab/core/entity"
"github.com/crawlab-team/crawlab/core/utils"
"github.com/gin-gonic/gin"
"github.com/spf13/viper"
)
func GetSystemInfo(c *gin.Context) {
info := &entity.SystemInfo{
Edition: viper.GetString("edition"),
Version: viper.GetString("version"),
Edition: utils.GetEdition(),
Version: utils.GetVersion(),
}
HandleSuccessWithData(c, info)
}

View File

@@ -7,22 +7,31 @@ import (
func PrintLogoWithWelcomeInfo() {
printLogo()
printSystemInfo()
printWelcomeInfo()
}
func printLogo() {
figure.NewColorFigure("Crawlab", "slant", "blue", true).Print()
fmt.Println("Welcome to use Crawlab: the ultimate distributed web crawling platform for efficient, scalable data extraction.")
fmt.Println()
}
func printSystemInfo() {
fmt.Println("System Info:")
fmt.Printf("- Version: %s (%s)\n", GetEditionLabel(), GetVersion())
fmt.Printf("- Node Type: %s\n", GetNodeTypeLabel())
fmt.Println()
}
func printWelcomeInfo() {
fmt.Println("Distributed web crawling platform for efficient, scalable data extraction.")
fmt.Println("For more information, please refer to the following resources:")
fmt.Println("- Website: https://crawlab.cn")
fmt.Println("- Documentation: https://docs.crawlab.cn")
fmt.Println("- GitHub: https://github.com/crawlab-team/crawlab")
if IsMaster() {
fmt.Println("Visit https://localhost:8080 for the web ui, once the server is ready.")
}
fmt.Println("- GitHub Repo: https://github.com/crawlab-team/crawlab")
fmt.Println()
if IsMaster() {
fmt.Println("Visit the web ui at https://localhost:8080 (please be patient, it takes a while to start up)")
fmt.Println()
}
}

28
core/utils/system.go Normal file
View File

@@ -0,0 +1,28 @@
package utils
import "github.com/spf13/viper"
func GetVersion() string {
return viper.GetString("version")
}
func GetEdition() string {
return viper.GetString("edition")
}
func GetEditionLabel() string {
if IsPro() {
return "Crawlab Pro"
} else {
return "Crawlab Community"
}
}
func GetNodeTypeLabel() string {
if IsMaster() {
return "Master"
} else {
return "Worker"
}
}

View File

@@ -65,9 +65,8 @@ verify_python() {
return 1
fi
pip_version=$(pip -V)
if [[ ! $pip_version =~ "python ${version}" ]]; then
echo "ERROR: pip version does not match. expected: \"python ${version}\", but actual is \"${pip_version}\""
if ! command -v pip &> /dev/null; then
echo "ERROR: pip is not installed"
return 1
fi
return 0