chore: 领域模型 & DTO
This commit is contained in:
2
interval/api/dto/doc.go
Normal file
2
interval/api/dto/doc.go
Normal file
@ -0,0 +1,2 @@
|
||||
// Package dto contains data transfer objects used in the interval API.
|
||||
package dto
|
||||
17
interval/api/dto/message.go
Normal file
17
interval/api/dto/message.go
Normal file
@ -0,0 +1,17 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"git.jinshen.cn/remilia/push-server/interval/model"
|
||||
)
|
||||
|
||||
type Message struct {
|
||||
Topic string `json:"topic"`
|
||||
Content string `json:"content"`
|
||||
}
|
||||
|
||||
func MessageFromModel(m model.Message) Message {
|
||||
return Message{
|
||||
Topic: string(m.Topic),
|
||||
Content: string(m.Content),
|
||||
}
|
||||
}
|
||||
17
interval/api/dto/subscription.go
Normal file
17
interval/api/dto/subscription.go
Normal file
@ -0,0 +1,17 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"git.jinshen.cn/remilia/push-server/interval/model"
|
||||
)
|
||||
|
||||
type Subscription struct {
|
||||
Topic string `json:"topic"`
|
||||
ClientID string `json:"client_id"`
|
||||
}
|
||||
|
||||
func SubscriptionFromModel(s model.Subscription) Subscription {
|
||||
return Subscription{
|
||||
Topic: string(s.Topic),
|
||||
ClientID: string(s.ClientID),
|
||||
}
|
||||
}
|
||||
6
interval/model/message.go
Normal file
6
interval/model/message.go
Normal file
@ -0,0 +1,6 @@
|
||||
package model
|
||||
|
||||
type Message struct {
|
||||
Topic Topic
|
||||
Content []byte
|
||||
}
|
||||
6
interval/model/subscription.go
Normal file
6
interval/model/subscription.go
Normal file
@ -0,0 +1,6 @@
|
||||
package model
|
||||
|
||||
type Subscription struct {
|
||||
Topic Topic
|
||||
ClientID string
|
||||
}
|
||||
7
interval/model/topic.go
Normal file
7
interval/model/topic.go
Normal file
@ -0,0 +1,7 @@
|
||||
package model
|
||||
|
||||
type Topic string
|
||||
|
||||
func (t Topic) Valid() bool {
|
||||
return t != ""
|
||||
}
|
||||
Reference in New Issue
Block a user