Page Menu
Home
Musing Studio
Search
Configure Global Search
Log In
Files
F12272557
user.go
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
932 B
Subscribers
None
user.go
View Options
package
config
import
(
"encoding/json"
"io/ioutil"
"path/filepath"
writeas
"github.com/writeas/go-writeas/v2"
"github.com/writeas/writeas-cli/fileutils"
)
const
UserFile
=
"user.json"
func
LoadUser
(
dataDir
string
)
(
*
writeas
.
AuthUser
,
error
)
{
fname
:=
filepath
.
Join
(
dataDir
,
UserFile
)
userJSON
,
err
:=
ioutil
.
ReadFile
(
fname
)
if
err
!=
nil
{
if
!
fileutils
.
Exists
(
fname
)
{
// Don't return a file-not-found error
return
nil
,
nil
}
return
nil
,
err
}
// Parse JSON file
u
:=
&
writeas
.
AuthUser
{}
err
=
json
.
Unmarshal
(
userJSON
,
u
)
if
err
!=
nil
{
return
nil
,
err
}
return
u
,
nil
}
func
SaveUser
(
dataDir
string
,
u
*
writeas
.
AuthUser
)
error
{
// Marshal struct into pretty-printed JSON
userJSON
,
err
:=
json
.
MarshalIndent
(
u
,
""
,
" "
)
if
err
!=
nil
{
return
err
}
// Save file
err
=
ioutil
.
WriteFile
(
filepath
.
Join
(
dataDir
,
UserFile
),
userJSON
,
0600
)
if
err
!=
nil
{
return
err
}
return
nil
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Nov 6, 4:46 AM (1 h, 45 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3472876
Attached To
rWCLI writeas-cli
Event Timeline
Log In to Comment