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
15 changed files
with
230 additions
and
62 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
File renamed without changes.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package hostfile | ||
|
||
import "github.com/txn2/txeh" | ||
|
||
type HostfileInterface interface { | ||
AddHost(ip, hostname string) error | ||
RemoveHost(hostname string) error | ||
} | ||
|
||
// Hostfile represents the host file manager client | ||
type Hostfile struct { | ||
hosts *txeh.Hosts | ||
} | ||
|
||
// NewClient returns a new Hostfile manager client | ||
func NewClient() (*Hostfile, error) { | ||
hosts, err := txeh.NewHostsDefault() | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
return &Hostfile{ | ||
hosts: hosts, | ||
}, err | ||
} | ||
|
||
// AddHost adds a new host / ip entry into the hosts file | ||
func (h *Hostfile) AddHost(ip, hostname string) error { | ||
h.hosts.Reload() | ||
h.hosts.AddHost(ip, hostname) | ||
err := h.hosts.Save() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// RemoveHost removes a given hostname from the hosts file | ||
func (h *Hostfile) RemoveHost(hostname string) error { | ||
h.hosts.Reload() | ||
h.hosts.RemoveHost(hostname) | ||
h.hosts.Save() | ||
|
||
return nil | ||
} |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.