Browse Source

Update documentation

master
Chris Wiegman 5 months ago
parent
commit
883358bf76
Signed by: chriswiegman <chris@chriswiegman.com> GPG Key ID: 2B23D7A74FDE2DF4
2 changed files with 33 additions and 23 deletions
  1. +18
    -15
      API.md
  2. +15
    -8
      README.md

+ 18
- 15
API.md View File

@@ -9,8 +9,10 @@

```go
type Hosts struct {
Path string
Lines []HostsLine
Path string
Section string
FileLines []HostsLine
SectionLines []HostsLine
}
```

@@ -19,10 +21,17 @@ Represents a hosts file.
#### func NewHosts

```go
func NewHosts() (Hosts, error)
func NewHosts("") (Hosts, error)
```
Return a new instance of ``Hosts``.

#### func IsComment

```go
func IsComment(line string) bool
```
Return ```true``` if the string is a comment.

#### func (*Hosts) Add

```go
@@ -40,7 +49,7 @@ Flush any changes made to hosts file.
#### func (Hosts) Has

```go
func (h Hosts) Has(ip string, host string, foreFile bool) bool
func (h Hosts) Has(ip string, host string, forceFile bool) bool
```
Return a bool if ip/host combo in hosts file.

@@ -71,10 +80,11 @@ Remove an entry from the hosts file.

```go
type HostsLine struct {
IP string
Hosts []string
Raw string
Err error
IP string
Hosts []string
Comment string
Raw string
Err error
}
```

@@ -86,10 +96,3 @@ Represents a single line in the hosts file.
func NewHostsLine(raw string) HostsLine
```
Return a new instance of ```HostsLine```.

#### func (HostsLine) IsComment

```go
func IsComment(line string) bool
```
Return ```true``` if the line is a comment.

+ 15
- 8
README.md View File

@@ -54,6 +54,12 @@ Or *entries*.
$ goodhosts rm 127.0.0.1 facebook.com twitter.com gmail.com
```

### Remove an section

```bash
$ goodhosts removesection sectionname
```

### More

```bash
@@ -79,7 +85,7 @@ import (
)

func main() {
hosts := goodhosts.NewHosts()
hosts := goodhosts.NewHosts("")

for _, line := range hosts.Lines {
fmt.Println(line.Raw)
@@ -98,9 +104,9 @@ import (
)

func main() {
hosts := goodhosts.NewHosts()
hosts := goodhosts.NewHosts("")

if hosts.Has("127.0.0.1", "facebook.com") {
if hosts.Has("127.0.0.1", "facebook.com", true) {
fmt.Println("Entry exists!")
return
}
@@ -120,7 +126,7 @@ import (
)

func main() {
hosts := goodhosts.NewHosts()
hosts := goodhosts.NewHosts("")

// Note that nothing will be added to the hosts file until ``hosts.Flush`` is called.
hosts.Add("127.0.0.1", "This is a line comment", "facebook.com", "twitter.com")
@@ -142,7 +148,7 @@ import (
)

func main() {
hosts := goodhosts.NewHosts()
hosts := goodhosts.NewHosts("")

// Same deal, yo: call hosts.Flush() to make permanent.
hosts.Remove("127.0.0.1", "facebook.com", "twitter.com")
@@ -158,12 +164,15 @@ func main() {
## Changelog

### 3.2 (2019-10-10)

* Add ability to remove an entire section

### 3.1.1 (2019-10-10)

* Fix existing tests

### 3.1 (2019-10-10)

* Allow sectioning of IP addresses with "section name" in api
* Various bugfixes

@@ -187,10 +196,8 @@ func main() {

### 1.0.0 (2015-05-03)

- Initial release.
* Initial release.

## License

[MIT](LICENSE)

<img src="http://static.messynessychic.com/wp-content/uploads/2013/08/rothschildparty2.jpg" width=400><br>

Loading…
Cancel
Save