https://github.com/suzuki-shunsuke/go-ptr
golang library to convert a literal to pointer
https://github.com/suzuki-shunsuke/go-ptr
golang library oss
Last synced: 9 months ago
JSON representation
golang library to convert a literal to pointer
- Host: GitHub
- URL: https://github.com/suzuki-shunsuke/go-ptr
- Owner: suzuki-shunsuke
- License: mit
- Created: 2018-04-18T01:08:54.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2024-02-27T11:33:47.000Z (over 2 years ago)
- Last Synced: 2024-04-15T01:18:27.589Z (about 2 years ago)
- Topics: golang, library, oss
- Language: Go
- Homepage: https://godoc.org/github.com/suzuki-shunsuke/go-ptr
- Size: 118 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 27
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# go-ptr
[](http://godoc.org/github.com/suzuki-shunsuke/go-ptr)
[](https://circleci.com/gh/suzuki-shunsuke/go-ptr)
[](https://codecov.io/gh/suzuki-shunsuke/go-ptr)
[](https://goreportcard.com/report/github.com/suzuki-shunsuke/go-ptr)
[](https://github.com/suzuki-shunsuke/go-ptr)
[](https://github.com/suzuki-shunsuke/go-ptr/releases)
[](https://raw.githubusercontent.com/suzuki-shunsuke/go-ptr/master/LICENSE)
golang library to convert a literal to pointer.
This library is very trivial.
If there are any other ways to get a pointer of the literal value, please tell us.
## Motivation
Sometimes we want to get a pointer of the literal value.
But the following code raises a compile error.
https://play.golang.org/p/p9E9omKHogv
```golang
package main
import (
"fmt"
)
func main() {
fmt.Println(&"hello")
}
```
```
prog.go:8:14: cannot take the address of "hello"
```
So we have to assign the literal to a variable.
```golang
a := "hello"
fmt.Println(&a)
```
But we want to write this at an one liner.
```golang
fmt.Println(ptr.PStr("hello"))
```
## License
[MIT](LICENSE)