All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.lyranthe.prometheus.client.LabelName.scala Maven / Gradle / Ivy

The newest version!
package org.lyranthe.prometheus.client

import scala.util.matching.Regex

case class LabelName(name: String) extends AnyVal

object LabelName {
  val PrometheusLabelFormat: Regex = """^[a-zA-Z_][a-zA-Z0-9_]*$""".r

  def unsafeFromString(s: String): LabelName = {
    PrometheusLabelFormat.findFirstIn(s) match {
      case None =>
        throw new IllegalArgumentException(
          s"$s does not match required label format ${PrometheusLabelFormat.regex}")
      case Some(formatted) =>
        LabelName(formatted)
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy