Skip to content
This repository was archived by the owner on Jun 3, 2019. It is now read-only.

Commit 2ef7892

Browse files
authored
Merge pull request #17 from travisbrown/feature/address
Add (type-safe) address to LocalService definition
2 parents 6ea6ac0 + a2c47e7 commit 2ef7892

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import consul.Consul
1818

1919
instanciate a consul supplying an ip and a port indicating a working consul agent:
2020
```scala
21-
val myConsul = new consul.Consul(CONSUL_IP, CONSUL_PORT)
21+
val myConsul = new consul.Consul(CONSUL_IP, CONSUL_PORT, Option(CONSUL_ACL_TOKEN))
2222
import myConsul.v1._
2323
```
2424

@@ -38,9 +38,10 @@ catalog.nodes().map{ case nodes =>
3838

3939
Example - register a service with an http-check on the local node:
4040
```scala
41+
val myAddress = "127.0.0.1"
4142
val myServicePort = 5000
4243
val myServiceCheck = agent.service.httpCheck(s"http://localhost:$myServicePort/health","15s")
43-
val myService = agent.service.LocalService(ServiceId("myServiceId"),ServiceType("myTypeOfService"),Set(ServiceTag("MyTag")),Some(myServicePort),Some(myServiceCheck))
44+
val myService = agent.service.LocalService(ServiceId("myServiceId"),ServiceType("myTypeOfService"),Set(ServiceTag("MyTag")),Some(myServicePort),Some(myServiceCheck),Some(Address(myAddress)))
4445
agent.service.register(myService)
4546
```
4647
the check ID of the registered service-check is available via:

src/main/scala/consul/v1/agent/service/LocalService.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package consul.v1.agent.service
22

3-
import consul.v1.common.Types.{CheckId, ServiceId, ServiceTag, ServiceType}
3+
import consul.v1.common.Types.{Address, CheckId, ServiceId, ServiceTag, ServiceType}
44
import play.api.libs.functional.syntax._
55
import play.api.libs.json._
66

7-
case class LocalService(ID: ServiceId, Name: ServiceType, Tags: Set[ServiceTag] = Set.empty, Port: Option[Int], Check: Option[Check]){
7+
case class LocalService(ID: ServiceId, Name: ServiceType, Tags: Set[ServiceTag] = Set.empty, Port: Option[Int], Check: Option[Check],
8+
Address: Option[Address] = None){
89
lazy val checkId:CheckId = CheckId(s"service:$ID")
910
}
1011

@@ -14,7 +15,8 @@ object LocalService {
1415
(__ \ "Name" ).write[ServiceType] and
1516
(__ \ "Tags" ).write[Set[ServiceTag]] and
1617
(__ \ "Port" ).write[Option[Int]] and
17-
(__ \ "Check").write[Option[Check]]
18+
(__ \ "Check").write[Option[Check]] and
19+
(__ \ "Address").write[Option[Address]]
1820
)( unlift(LocalService.unapply) )
1921

2022
//no id is provided -> id becomes name

src/main/scala/consul/v1/common/Types.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ trait Types {
2323

2424
type DatacenterId = WrappedType[String,DatacenterIds]
2525
def DatacenterId: String => DatacenterId = WrappedType.apply
26+
27+
type Address = WrappedType[String, Addresses]
28+
def Address: String => Address = WrappedType.apply
2629
}
2730

2831
object Types extends Types{
@@ -33,6 +36,7 @@ object Types extends Types{
3336
sealed trait ServiceTypes
3437
sealed trait ServiceTags
3538
sealed trait DatacenterIds
39+
sealed trait Addresses
3640

3741
case class ConsulResponseParseException(error:JsError) extends Throwable
3842
}

0 commit comments

Comments
 (0)