Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] Common lib #3

Open
iglov opened this issue Sep 27, 2024 · 0 comments
Open

[feature] Common lib #3

iglov opened this issue Sep 27, 2024 · 0 comments

Comments

@iglov
Copy link
Owner

iglov commented Sep 27, 2024

Write common lib for:

// Helper function to capitalize the first letter of a string.
func capitalizeManufacturer(manufacturer string) string {
	if len(manufacturer) == 0 {
		return manufacturer
	}
	return strings.ToUpper(manufacturer[:1]) + strings.ToLower(manufacturer[1:])
}
// Read one-liner text files, strip newline.
func slurpFile(path string) string {
	data, err := os.ReadFile(path)
	if err != nil {
		return ""
	}
	return strings.TrimSpace(string(data))
}

// If a deferred function has any return values, they are discarded when the function completes.
func Check(f func() error) {
	if err := f(); err != nil {
		fmt.Println("Received error:", err)
	}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant