Some checks failed
CI / Run tests and lints (push) Failing after 29s
CI / Build CLI docs (push) Has been skipped
CI / Run Playwright end-to-end tests (mysql) (push) Failing after 3s
CI / Run Playwright end-to-end tests (postgres) (push) Failing after 2s
CI / Run Playwright end-to-end tests (sqlite) (push) Failing after 3s
CodeQL / Analyze (go) (push) Failing after 4s
CodeQL / Analyze (javascript) (push) Failing after 3s
Docker Image Scanners / scanners (push) Failing after 4s
Synchronize Issue Labels / Synchronize Issue Labels (push) Has been skipped
CI / Run end-to-end tests (postgres) (push) Failing after 19s
CI / Run end-to-end tests (sqlite) (push) Failing after 2s
CI / Run Playwright end-to-end tests (cockroach) (push) Failing after 2s
CI / Draft newsletter (push) Has been skipped
CI / Generate release (push) Has been skipped
CI / Pending approval Slack notification (push) Has been skipped
CI / Send newsletter (push) Has been skipped
90 lines
1.5 KiB
Go
90 lines
1.5 KiB
Go
// Copyright © 2023 Ory Corp
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package text
|
|
|
|
import (
|
|
"database/sql/driver"
|
|
"encoding/json"
|
|
|
|
"github.com/ory/x/sqlxx"
|
|
)
|
|
|
|
// swagger:model uiTexts
|
|
type Messages []Message
|
|
|
|
func (h Messages) MarshalJSON() ([]byte, error) {
|
|
if len(h) == 0 {
|
|
return []byte("[]"), nil
|
|
}
|
|
|
|
return json.Marshal([]Message(h))
|
|
}
|
|
|
|
func (h *Messages) Scan(value interface{}) error {
|
|
return sqlxx.JSONScan(h, value)
|
|
}
|
|
|
|
func (h Messages) Value() (driver.Value, error) {
|
|
if h == nil {
|
|
return []byte("[]"), nil
|
|
}
|
|
return json.Marshal(h)
|
|
}
|
|
|
|
func (h *Messages) Add(m *Message) Messages {
|
|
*h = append(*h, *m)
|
|
return *h
|
|
}
|
|
|
|
func (h *Messages) Set(m *Message) Messages {
|
|
*h = Messages{*m}
|
|
return *h
|
|
}
|
|
|
|
func (h *Messages) Clear() Messages {
|
|
*h = *new(Messages)
|
|
return *h
|
|
}
|
|
|
|
// swagger:model uiText
|
|
type Message struct {
|
|
// The message ID.
|
|
//
|
|
// required: true
|
|
ID ID `json:"id"`
|
|
|
|
// The message text. Written in american english.
|
|
//
|
|
// required: true
|
|
Text string `json:"text"`
|
|
|
|
// The message type.
|
|
//
|
|
// required: true
|
|
Type UITextType `json:"type"`
|
|
|
|
// The message's context. Useful when customizing messages.
|
|
Context json.RawMessage `json:"context,omitempty" faker:"-"`
|
|
}
|
|
|
|
func (m *Message) Scan(value interface{}) error {
|
|
return sqlxx.JSONScan(m, value)
|
|
}
|
|
|
|
func (m Message) Value() (driver.Value, error) {
|
|
return json.Marshal(&m)
|
|
}
|
|
|
|
func (m *Message) Error() string {
|
|
return m.Text
|
|
}
|
|
|
|
func (m *Message) Is(err error) bool {
|
|
em, ok := err.(*Message)
|
|
if !ok {
|
|
return false
|
|
}
|
|
return m.ID == em.ID
|
|
}
|