Why: Allow consumers to download an immutable module revision without nested source checkouts or local path replacements. Evidence: SELF package tests and the prior canonical-path rejection are recorded in the Dev dependency-workspace task card; remote consumption is replayed against the committed candidate. Impact: Change the module identity and its Go imports while preserving API behavior. Existing historical submodule revisions remain buildable. Refs: Versioned dependencies U1/U3; feature/dependency-workspace
36 lines
900 B
Go
36 lines
900 B
Go
package domains
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
"git-ssh.u1680832.nyat.app/weichen/Error-Code-System.git/errcode"
|
|
)
|
|
|
|
// ExportDomain 导出单个域的定义 JSON(字典序)。
|
|
func ExportDomain(r *errcode.Registry, domain string) ([]byte, error) {
|
|
buf := &bytes.Buffer{}
|
|
enc := json.NewEncoder(buf)
|
|
enc.SetEscapeHTML(false)
|
|
enc.SetIndent("", " ")
|
|
if err := enc.Encode(r.List(domain)); err != nil {
|
|
return nil, err
|
|
}
|
|
return buf.Bytes(), nil
|
|
}
|
|
|
|
// DomainOf 返回定义切片中的域;混合域或空切片返回错误。
|
|
func DomainOf(defs []errcode.Definition) (string, error) {
|
|
if len(defs) == 0 {
|
|
return "", fmt.Errorf("domains: empty catalog")
|
|
}
|
|
domain := defs[0].Code.Domain()
|
|
for _, def := range defs[1:] {
|
|
if def.Code.Domain() != domain {
|
|
return "", fmt.Errorf("domains: mixed domains %s and %s", domain, def.Code.Domain())
|
|
}
|
|
}
|
|
return domain, nil
|
|
}
|