From 5deadfe00c9740c4b939d69d6c460ac23ce5027d Mon Sep 17 00:00:00 2001 From: akushman Date: Tue, 19 Mar 2019 09:51:17 +0300 Subject: [PATCH] #17. Add list-links to readme --- README.md | 55 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index bc8550c..a6fd83d 100644 --- a/README.md +++ b/README.md @@ -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: @@ -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" @@ -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 := "
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
" + +str := html.StripTags(html, []string{"a", "span"}) // results in: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt 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) ``` @@ -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 := "
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
" - -str := html.StripTags(html, []string{"a", "span"}) // results in: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt 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 { @@ -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