Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:recycle: Simplify pointer initialization with new expressions

Daniela889d693e70f
diff --git a/kernel/agent/attachments_test.go b/kernel/agent/attachments_test.go
index 97663338a8..20900942db 100644
--- a/kernel/agent/attachments_test.go
+++ b/kernel/agent/attachments_test.go
@@ -131,8 +131,6 @@ func TestDowngradeImageInputPreservesTextWithoutMutatingHistory(t *testing.T) {
}
func TestImageInputUnsupportedErrorClassification(t *testing.T) {
- param := "messages.2.content.1.type"
- detailParam := "messages.2.content.1.image_url.detail"
tests := []struct {
name string
err error
@@ -143,7 +141,7 @@ func TestImageInputUnsupportedErrorClassification(t *testing.T) {
err: &openai.APIError{
HTTPStatusCode: 400,
Message: "This model does not support image input",
- Param: &param,
+ Param: new("messages.2.content.1.type"),
},
want: true,
},
@@ -195,7 +193,7 @@ func TestImageInputUnsupportedErrorClassification(t *testing.T) {
err: &openai.APIError{
HTTPStatusCode: 400,
Message: "Unsupported parameter",
- Param: &detailParam,
+ Param: new("messages.2.content.1.image_url.detail"),
},
},
{
diff --git a/kernel/agent/compaction_test.go b/kernel/agent/compaction_test.go
index 48ce68d33e..473fc44b3e 100644
--- a/kernel/agent/compaction_test.go
+++ b/kernel/agent/compaction_test.go
@@ -374,7 +374,7 @@ func TestAgentChatRegenerateCompactionUsesTruncatedEditedHistory(t *testing.T) {
events := AgentChat(
context.Background(), newTestOpenAIClient(server.URL), "test-model", "", contextLimit, testSessionID,
- "user-2", 1, editedTarget, stringPointer(editedBlockHTML), "English", nil, EditorContext{}, nil, true,
+ "user-2", 1, editedTarget, new(editedBlockHTML), "English", nil, EditorContext{}, nil, true,
time.Second, 0, "", time.Second, time.Second,
)
for event := range events {
diff --git a/kernel/agent/session_test.go b/kernel/agent/session_test.go
index a5e2d88a6d..1bdc469ad0 100644
--- a/kernel/agent/session_test.go
+++ b/kernel/agent/session_test.go
@@ -39,10 +39,6 @@ func marshalSession(t *testing.T, value any) []byte {
return data
}
-func stringPointer(value string) *string {
- return &value
-}
-
func TestSaveSessionRevisionConflictAndUnknownFields(t *testing.T) {
useTestDataDir(t)
base := map[string]any{
@@ -345,7 +341,7 @@ func TestRegenerateRuntimeRecoveryKeepsEditedUserContent(t *testing.T) {
}},
}
emptyReferences := []Reference{}
- turn.UserBlockHTML = stringPointer(editedBlockHTML)
+ turn.UserBlockHTML = new(editedBlockHTML)
turn.UserReferences = &emptyReferences
turn.UserEditorContext = &EditorContext{ActiveDocID: "new-doc"}
if err := beginRuntimeTurn(testSessionID, turn, false); err != nil {
@@ -689,7 +685,7 @@ func TestApplyRegenerateRuntimeReplacesUserContent(t *testing.T) {
Mode: "regenerate",
UserEntryID: "user-1",
UserContent: "edited prompt",
- UserBlockHTML: stringPointer(editedBlockHTML),
+ UserBlockHTML: new(editedBlockHTML),
UpdatedAt: 1,
Delta: []AgentMessage{{
Role: "assistant",
@@ -754,7 +750,7 @@ func TestApplyRegenerateRuntimeClearsEditedUserBlockHTML(t *testing.T) {
Mode: "regenerate",
UserEntryID: "user-1",
UserContent: "edited prompt",
- UserBlockHTML: stringPointer(""),
+ UserBlockHTML: new(""),
UpdatedAt: 1,
}
if err := applyRuntimeTurnToSessionLocked(session, turn); err != nil {
diff --git a/kernel/api/setting.go b/kernel/api/setting.go
index 21eb3479de..b524bd1f24 100644
--- a/kernel/api/setting.go
+++ b/kernel/api/setting.go
@@ -423,8 +423,7 @@ func setEditor(c *gin.Context) {
}
if nil == editor.FloatWindowDelay {
- v := 620
- editor.FloatWindowDelay = &v
+ editor.FloatWindowDelay = new(620)
} else {
*editor.FloatWindowDelay = max(0, min(2000, *editor.FloatWindowDelay))
}
diff --git a/kernel/conf/editor.go b/kernel/conf/editor.go
index e4ebdc5cdf..f3526dcd0a 100644
--- a/kernel/conf/editor.go
+++ b/kernel/conf/editor.go
@@ -87,11 +87,11 @@ func NewEditor() *Editor {
CodeLigatures: false,
DisplayBookmarkIcon: true,
DisplayNetImgMark: true,
- DatabaseAttrShow: func() *bool { value := true; return &value }(),
+ DatabaseAttrShow: new(true),
DatabaseAttrClickMode: 0,
DatabaseAttrViewMode: 0,
DatabaseAttrHideEmpty: false,
- DatabaseAttrUseTabs: func() *bool { value := true; return &value }(),
+ DatabaseAttrUseTabs: new(true),
GenerateHistoryInterval: 10,
HistoryRetentionDays: 30,
Emoji: []string{},
@@ -105,7 +105,7 @@ func NewEditor() *Editor {
ListLogicalOutdent: false,
ListItemDotNumberClickFocus: true,
FloatWindowMode: 0,
- FloatWindowDelay: func() *int { v := 620; return &v }(),
+ FloatWindowDelay: new(620),
DynamicLoadBlocks: 192,
Justify: false,
RTL: false,
@@ -115,8 +115,8 @@ func NewEditor() *Editor {
BackmentionExpandCount: -1,
BacklinkContainChildren: true,
BacklinkShowBottom: false,
- BacklinkSort: func() *int { v := util.SortModeUpdatedDESC; return &v }(),
- BackmentionSort: func() *int { v := util.SortModeUpdatedDESC; return &v }(),
+ BacklinkSort: new(util.SortModeUpdatedDESC),
+ BackmentionSort: new(util.SortModeUpdatedDESC),
HeadingNumber: false,
HeadingNumberFormat: DefaultHeadingNumberFormat,
HeadingEmbedMode: 0,
diff --git a/kernel/model/bazaar.go b/kernel/model/bazaar.go
index 46ff74554d..ece992a2eb 100644
--- a/kernel/model/bazaar.go
+++ b/kernel/model/bazaar.go
@@ -321,16 +321,13 @@ func getInstalledPackages0(pkgType, frontend, keyword string) (installedPackages
for _, pkg := range installedPackages {
switch pkgType {
case "plugins":
- installedIncompatible := bazaar.IsIncompatiblePlugin(pkg, frontend)
- pkg.InstalledIncompatible = &installedIncompatible
+ pkg.InstalledIncompatible = new(bazaar.IsIncompatiblePlugin(pkg, frontend))
petal := getPetalByName(pkg.Name, petals)
if nil != petal {
- enabled := petal.Enabled
- pkg.Enabled = &enabled
+ pkg.Enabled = new(petal.Enabled)
}
case "themes":
- installedIncompatible := bazaar.IsIncompatibleTheme(pkg, frontend)
- pkg.InstalledIncompatible = &installedIncompatible
+ pkg.InstalledIncompatible = new(bazaar.IsIncompatibleTheme(pkg, frontend))
pkg.Current = pkg.Name == Conf.Appearance.ThemeDark || pkg.Name == Conf.Appearance.ThemeLight
case "icons":
pkg.Current = pkg.Name == Conf.Appearance.Icon
diff --git a/kernel/model/conf.go b/kernel/model/conf.go
index 7ecdf83882..26440c089a 100644
--- a/kernel/model/conf.go
+++ b/kernel/model/conf.go
@@ -429,7 +429,7 @@ func InitConf() {
}
util.LargeFileWarningSize = Conf.FileTree.LargeFileWarningSize
if nil == Conf.FileTree.CreateDocAtTop { // v3.4.0 之前的版本没有该字段,设置默认值为 true,即在顶部创建新文档,不改变用户习惯
- Conf.FileTree.CreateDocAtTop = func() *bool { b := true; return &b }()
+ Conf.FileTree.CreateDocAtTop = new(true)
}
if nil == Conf.FileTree.BoxDocEnabled {
// 配置缺失时默认关闭顶层笔记本文档。
@@ -490,8 +490,7 @@ func InitConf() {
Conf.Editor.HistoryRetentionDays = 3650
}
if nil == Conf.Editor.FloatWindowDelay {
- v := 620
- Conf.Editor.FloatWindowDelay = &v
+ Conf.Editor.FloatWindowDelay = new(620)
} else {
*Conf.Editor.FloatWindowDelay = max(0, min(2000, *Conf.Editor.FloatWindowDelay))
}
diff --git a/kernel/model/export.go b/kernel/model/export.go
index b94a456d9b..ede23c282f 100644
--- a/kernel/model/export.go
+++ b/kernel/model/export.go
@@ -2153,57 +2153,44 @@ func ParseExportOptions(arg map[string]any) (opts *ExportOptions) {
opts = &ExportOptions{}
// 通用部分
if nil != arg["addTitle"] {
- v := arg["addTitle"].(bool)
- opts.AddTitle = &v
+ opts.AddTitle = new(arg["addTitle"].(bool))
}
if nil != arg["inlineMemo"] {
- v := arg["inlineMemo"].(bool)
- opts.InlineMemo = &v
+ opts.InlineMemo = new(arg["inlineMemo"].(bool))
}
if nil != arg["blockRefMode"] {
- v := int(arg["blockRefMode"].(float64))
- opts.BlockRefMode = &v
+ opts.BlockRefMode = new(int(arg["blockRefMode"].(float64)))
}
if nil != arg["blockEmbedMode"] {
- v := int(arg["blockEmbedMode"].(float64))
- opts.BlockEmbedMode = &v
+ opts.BlockEmbedMode = new(int(arg["blockEmbedMode"].(float64)))
}
if nil != arg["fileAnnotationRefMode"] {
- v := int(arg["fileAnnotationRefMode"].(float64))
- opts.FileAnnotationRefMode = &v
+ opts.FileAnnotationRefMode = new(int(arg["fileAnnotationRefMode"].(float64)))
}
if nil != arg["blockRefTextLeft"] {
- v := arg["blockRefTextLeft"].(string)
- opts.BlockRefTextLeft = &v
+ opts.BlockRefTextLeft = new(arg["blockRefTextLeft"].(string))
}
if nil != arg["blockRefTextRight"] {
- v := arg["blockRefTextRight"].(string)
- opts.BlockRefTextRight = &v
+ opts.BlockRefTextRight = new(arg["blockRefTextRight"].(string))
}
if nil != arg["tagOpenMarker"] {
- v := arg["tagOpenMarker"].(string)
- opts.TagOpenMarker = &v
+ opts.TagOpenMarker = new(arg["tagOpenMarker"].(string))
}
if nil != arg["tagCloseMarker"] {
- v := arg["tagCloseMarker"].(string)
- opts.TagCloseMarker = &v
+ opts.TagCloseMarker = new(arg["tagCloseMarker"].(string))
}
// Markdown 专属部分
if nil != arg["includeSubDocs"] {
- v := arg["includeSubDocs"].(bool)
- opts.IncludeSubDocs = &v
+ opts.IncludeSubDocs = new(arg["includeSubDocs"].(bool))
}
if nil != arg["includeRelatedDocs"] {
- v := arg["includeRelatedDocs"].(bool)
- opts.IncludeRelatedDocs = &v
+ opts.IncludeRelatedDocs = new(arg["includeRelatedDocs"].(bool))
}
if nil != arg["markdownYFM"] {
- v := arg["markdownYFM"].(bool)
- opts.MarkdownYFM = &v
+ opts.MarkdownYFM = new(arg["markdownYFM"].(bool))
}
if nil != arg["removeAssetsID"] {
- v := arg["removeAssetsID"].(bool)
- opts.RemoveAssetsID = &v
+ opts.RemoveAssetsID = new(arg["removeAssetsID"].(bool))
}
return
}
diff --git a/kernel/util/appearance.go b/kernel/util/appearance.go
index 3f714ffc7f..2bebde78b9 100644
--- a/kernel/util/appearance.go
+++ b/kernel/util/appearance.go
@@ -38,13 +38,12 @@ type Notifications struct {
// NewNotifications 创建默认全部启用的通知配置。新增内置通知时在此统一调整默认值,避免多处分散。
func NewNotifications() *Notifications {
- selectAllTip := true
return &Notifications{
DocTreeMaxList: true,
TagMaxList: true,
WorkspaceNotSSD: true,
BrowserCompatibility: true,
- SelectAllTip: &selectAllTip,
+ SelectAllTip: new(true),
}
}
diff --git a/kernel/util/lute.go b/kernel/util/lute.go
index e94ce69be1..710a150266 100644
--- a/kernel/util/lute.go
+++ b/kernel/util/lute.go
@@ -35,7 +35,7 @@ var MarkdownSettings = &Markdown{
InlineMath: true,
InlineStrikethrough: true,
InlineMark: true,
- CodeBlockMiddleDot: func() *bool { value := true; return &value }(),
+ CodeBlockMiddleDot: new(true),
}
type Markdown struct {
diff --git a/kernel/util/working.go b/kernel/util/working.go
index ae561a8cd6..796c19a1c9 100644
--- a/kernel/util/working.go
+++ b/kernel/util/working.go
@@ -83,8 +83,7 @@ var (
// the commandline parameter itself.
func coalesceToEnvVar(fromCLI *string, envVarName string) *string {
if fromCLI == nil || "" == *fromCLI {
- ret := os.Getenv(envVarName)
- return &ret
+ return new(os.Getenv(envVarName))
}
return fromCLI
}