Skip to content

Commit

Permalink
#17. Add list-links to readme
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurkushman committed Mar 19, 2019
1 parent bd698a4 commit 5deadfe
Showing 1 changed file with 34 additions and 21 deletions.
55 changes: 34 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ Go library for PHP community with convenient functions
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
[![GoDoc](https://github.com/golang/gddo/blob/c782c79e0a3c3282dacdaaebeff9e6fd99cb2919/gddo-server/assets/status.svg)](https://godoc.org/github.com/arthurkushman/pgo)

* [Installation](#user-content-installation)
* [Date](#user-content-date)
* [Strings](#user-content-strings)
* [Files](#user-content-files)
* [Arrays](#user-content-arrays)

#### Installation

Via go get command:
Expand All @@ -16,13 +22,16 @@ go get github.com/arthurkushman/pgo

Imagine that you need to write Go code every day and also have a convenient functions in memory from PHP experience

#### You can use date function with similar formatting for PHP e.g.:
### Date
You can use date function with similar formatting for PHP e.g.:

```go
dateStr := pgo.Date("Y-m-d H:i:s")
```

replace sub-strings with StrReplace:
### Strings

#### replace sub-strings with StrReplace:
```go
subject := "The quick brown fox jumped over the lazy dog"

Expand All @@ -31,7 +40,27 @@ str, err := pgo.StrReplace([]string{"fox", "dog"}, []string{"cat", "elephant"},
// and if case-insensitive replace needed - pgo.StrIReplace([]string{"DOG", "QuiCK"}, []string{"fox", "slow"}, subject)
```

#### Read files with offset/limit:
#### Bulding a http query string:
```go
queryStr := pgo.HTTPBuildQuery(map[string]string{
"foo": "bar",
"bar": "baz",
}) // bar=baz&foo=bar
```

#### Strip tags with exclusion rules:
```go
html := "<div>Lorem <span>ipsum dolor sit amet</span>, consectetur adipiscing elit, sed do eiusmod <a href=\"http://example.com\">tempor incididunt</a> ut labore <strong>et dolore</strong> magna aliqua.</div>"

str := html.StripTags(html, []string{"a", "span"}) // results in: "Lorem <span>ipsum dolor sit amet</span>, consectetur adipiscing elit, sed do eiusmod <a href=\"http://example.com\">tempor incididunt</a> ut labore et dolore magna aliqua."
```
UPD: As had been stated here - https://github.com/golang/go/issues/22639
There is a very handy "stripTags" function in html/template, then guys from official team as fast as they got dislike on their negative comment, closed the thread.
That is why libs like `pgo` is appearing and will be move forward/evelove, bypassing strict rules that sometimes looking nonsence.

### Files

Read files with offset/limit:
```go
content, err := pgo.FileGetContents("somefile.txt", 0, 1024)
```
Expand All @@ -55,24 +84,6 @@ ctx.UploadMaxFileSize = 10 << 25
uploaded := ctx.MoveUploadedFile("foo", "/srv/images/pic123.png")
```

#### Bulding a http query string:
```go
queryStr := pgo.HTTPBuildQuery(map[string]string{
"foo": "bar",
"bar": "baz",
}) // bar=baz&foo=bar
```

#### Strip tags with exclusion rules:
```go
html := "<div>Lorem <span>ipsum dolor sit amet</span>, consectetur adipiscing elit, sed do eiusmod <a href=\"http://example.com\">tempor incididunt</a> ut labore <strong>et dolore</strong> magna aliqua.</div>"

str := html.StripTags(html, []string{"a", "span"}) // results in: "Lorem <span>ipsum dolor sit amet</span>, consectetur adipiscing elit, sed do eiusmod <a href=\"http://example.com\">tempor incididunt</a> ut labore et dolore magna aliqua."
```
UPD: As had been stated here - https://github.com/golang/go/issues/22639
There is a very handy "stripTags" function in html/template, then guys from official team as fast as they got dislike on their negative comment, closed the thread.
That is why libs like `pgo` is appearing and will be move forward/evelove, bypassing strict rules that sometimes looking nonsence.

#### Checking for file existence
```go
if pgo.FileExists("file1.txt") == true {
Expand All @@ -95,6 +106,8 @@ if pgo.IsLink("someLink") {
}
```

### Arrays

#### Check if an array contains an element
```go
pgo.InArray(3, []int{1, 2, 3}) // true
Expand Down

0 comments on commit 5deadfe

Please sign in to comment.