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

Use more idiomatic Kotlin in example for "Map Health Indicators to Micrometer Metrics" #37491

Closed
wants to merge 1 commit into from

Conversation

esperar
Copy link
Contributor

@esperar esperar commented Sep 20, 2023

Please understand that I am not good at grammar because I am not an English speaker..

Hello, I am a 16-year-old developer who lives in Korea., I was looking at the spring docs part developed by Kotlin and saw MyHealth Metrics ExportConfiguration's private fun getStatusCode(). It was using the if statement to return it, so I suggest using a when statement while using Kotlin!


Before

private fun getStatusCode(health: HealthEndpoint): Int {
		val status = health.health().status
		if (Status.UP == status) {
			return 3
		}
		if (Status.OUT_OF_SERVICE == status) {
			return 2
		}
		if (Status.DOWN == status) {
			return 1
		}
		return 0
	}

After

private fun getStatusCode(health: HealthEndpoint): Int {
    	return when (health.health().status) {
        	Status.UP -> 3
        	Status.OUT_OF_SERVICE -> 2
        	Status.DOWN -> 1
        	else -> 0
    	}
}

or

private fun getStatusCode(health: HealthEndpoint) = when (health.health().status) {
    Status.UP -> 3
    Status.OUT_OF_SERVICE -> 2
    Status.DOWN -> 1
    else -> 0
}

If you want to apply the second option, please leave a comment I'll change it.

Thank you :)

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Sep 20, 2023
@wilkinsona wilkinsona changed the title Simplify MyHealthMetricsExportConfiguration's private fun getStatusCode() Use more idiomatic Kotlin in example for "Map Health Indicators to Micrometer Metrics" Sep 20, 2023
@wilkinsona wilkinsona added type: documentation A documentation update and removed status: waiting-for-triage An issue we've not yet triaged labels Sep 20, 2023
@wilkinsona wilkinsona added this to the 2.7.x milestone Sep 20, 2023
@wilkinsona
Copy link
Member

This is great. Thanks very much, @esperar.

@mhalbritter
Copy link
Contributor

Thank you very much and congratulations on your first contribution 🎉!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: documentation A documentation update
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants