This repository has been archived by the owner on Feb 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
104 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,71 @@ | ||
package gohost | ||
|
||
type SysHost struct { | ||
HostsEnable map[int]struct{} | ||
import ( | ||
"gohost/config" | ||
"os" | ||
"sync" | ||
) | ||
|
||
type sysHost struct { | ||
name string | ||
desc string | ||
} | ||
|
||
var ( | ||
sysHostOnce sync.Once | ||
sysHostInstance *sysHost | ||
) | ||
|
||
func SysHost() Host { | ||
sysHostOnce.Do(func() { | ||
sysHostInstance = &sysHost{ | ||
name: "System Host", | ||
desc: config.Instance().SysHostFile, | ||
} | ||
}) | ||
return sysHostInstance | ||
} | ||
|
||
// Implement of Host | ||
var _ Host = (*sysHost)(nil) | ||
|
||
func (s *sysHost) FilterValue() string { | ||
return s.name | ||
} | ||
|
||
func (s *sysHost) GetParentID() string { | ||
panic("implement me") | ||
} | ||
|
||
func (s *sysHost) GetID() string { | ||
panic("implement me") | ||
} | ||
|
||
func (s *sysHost) GetName() string { | ||
//TODO implement me | ||
return s.name | ||
} | ||
|
||
func (s *sysHost) GetContent() []byte { | ||
hosts, err := os.ReadFile(config.Instance().SysHostFile) | ||
if err != nil { | ||
return []byte("Can not open system hosts file: \n" + err.Error()) | ||
} | ||
return hosts | ||
} | ||
|
||
func (s *sysHost) SetContent(content []byte) { | ||
panic("implement me") | ||
} | ||
|
||
func (s *sysHost) GetDesc() string { | ||
return s.desc | ||
} | ||
|
||
func (s *sysHost) GetGroupID() string { | ||
panic("implement me") | ||
} | ||
|
||
func (s *sysHost) IsEnabled() bool { | ||
return true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters