Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
beego
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
beego
Commits
9252301f
Commit
9252301f
authored
May 04, 2015
by
mlgd
Committed by
astaxie
May 25, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix save config ini file
parent
1053b63b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
15 deletions
+39
-15
ini.go
config/ini.go
+39
-15
No files found.
config/ini.go
View file @
9252301f
...
...
@@ -300,21 +300,8 @@ func (c *IniConfigContainer) SaveConfigFile(filename string) (err error) {
defer
f
.
Close
()
buf
:=
bytes
.
NewBuffer
(
nil
)
for
section
,
dt
:=
range
c
.
data
{
// Write section comments.
if
v
,
ok
:=
c
.
sectionComment
[
section
];
ok
{
if
_
,
err
=
buf
.
WriteString
(
string
(
bNumComment
)
+
v
+
lineBreak
);
err
!=
nil
{
return
err
}
}
if
section
!=
DEFAULT_SECTION
{
// Write section name.
if
_
,
err
=
buf
.
WriteString
(
string
(
sectionStart
)
+
section
+
string
(
sectionEnd
)
+
lineBreak
);
err
!=
nil
{
return
err
}
}
// Save default section at first place
if
dt
,
ok
:=
c
.
data
[
DEFAULT_SECTION
];
ok
{
for
key
,
val
:=
range
dt
{
if
key
!=
" "
{
// Write key comments.
...
...
@@ -336,6 +323,43 @@ func (c *IniConfigContainer) SaveConfigFile(filename string) (err error) {
return
err
}
}
// Save named sections
for
section
,
dt
:=
range
c
.
data
{
if
section
!=
DEFAULT_SECTION
{
// Write section comments.
if
v
,
ok
:=
c
.
sectionComment
[
section
];
ok
{
if
_
,
err
=
buf
.
WriteString
(
string
(
bNumComment
)
+
v
+
lineBreak
);
err
!=
nil
{
return
err
}
}
// Write section name.
if
_
,
err
=
buf
.
WriteString
(
string
(
sectionStart
)
+
section
+
string
(
sectionEnd
)
+
lineBreak
);
err
!=
nil
{
return
err
}
for
key
,
val
:=
range
dt
{
if
key
!=
" "
{
// Write key comments.
if
v
,
ok
:=
c
.
keyComment
[
key
];
ok
{
if
_
,
err
=
buf
.
WriteString
(
string
(
bNumComment
)
+
v
+
lineBreak
);
err
!=
nil
{
return
err
}
}
// Write key and value.
if
_
,
err
=
buf
.
WriteString
(
key
+
string
(
bEqual
)
+
val
+
lineBreak
);
err
!=
nil
{
return
err
}
}
}
// Put a line between sections.
if
_
,
err
=
buf
.
WriteString
(
lineBreak
);
err
!=
nil
{
return
err
}
}
}
if
_
,
err
=
buf
.
WriteTo
(
f
);
err
!=
nil
{
return
err
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment