Skip to content

Commit

Permalink
feat: refactor system info retrieval and enhance logo output
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
tikazyq committed Dec 29, 2024
1 parent a8bf115 commit 5480097
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 10 deletions.
6 changes: 3 additions & 3 deletions core/controllers/system_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
17 changes: 13 additions & 4 deletions core/utils/logo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
fmt.Println("- GitHub Repo: https://github.com/crawlab-team/crawlab")
fmt.Println()
if IsMaster() {
fmt.Println("Visit https://localhost:8080 for the web ui, once the server is ready.")
fmt.Println("Visit the web ui at https://localhost:8080 (please be patient, it takes a while to start up)")
fmt.Println()
}
fmt.Println()
}
28 changes: 28 additions & 0 deletions core/utils/system.go
Original file line number Diff line number Diff line change
@@ -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"
}
}
5 changes: 2 additions & 3 deletions docker/base-image/install/python/python.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5480097

Please sign in to comment.