enhancement: add graph invite endpoint (#7687)
This commit is contained in:
+2
-1
@@ -8,4 +8,5 @@
|
||||
*.out
|
||||
*.txt
|
||||
|
||||
vendor/
|
||||
vendor/
|
||||
/removecomments
|
||||
-18
@@ -1,18 +0,0 @@
|
||||
language: go
|
||||
|
||||
go:
|
||||
- 1.9.x
|
||||
- 1.10.x
|
||||
- 1.11.x
|
||||
- 1.12.x
|
||||
- 1.13.x
|
||||
- tip
|
||||
|
||||
before_install:
|
||||
- go get -t -v ./...
|
||||
|
||||
script:
|
||||
- go test -race -coverprofile=coverage.txt -covermode=atomic
|
||||
|
||||
after_success:
|
||||
- bash <(curl -s https://codecov.io/bash)
|
||||
+27
-1
@@ -1,4 +1,4 @@
|
||||
[](https://travis-ci.org/leodido/go-urn) [](https://codecov.io/gh/leodido/go-urn) [](https://godoc.org/github.com/leodido/go-urn)
|
||||
[](https://app.circleci.com/pipelines/github/leodido/go-urn) [](https://codecov.io/gh/leodido/go-urn) [](https://godoc.org/github.com/leodido/go-urn)
|
||||
|
||||
**A parser for URNs**.
|
||||
|
||||
@@ -52,4 +52,30 @@ no/19/urn:UrN:NSS__________________________________/-4 20000000 399 ns
|
||||
|
||||
---
|
||||
|
||||
## Example
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/leodido/go-urn"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var uid = "URN:foo:a123,456"
|
||||
|
||||
u, ok := urn.Parse([]byte(uid))
|
||||
if !ok {
|
||||
panic("error parsing urn")
|
||||
}
|
||||
|
||||
fmt.Println(u.ID)
|
||||
fmt.Println(u.SS)
|
||||
|
||||
// Output:
|
||||
// foo
|
||||
// a123,456
|
||||
}
|
||||
```
|
||||
|
||||
[](https://github.com/igrigorik/ga-beacon)
|
||||
-3
@@ -61,11 +61,9 @@ func (m *machine) Parse(input []byte) (*URN, error) {
|
||||
m.err = nil
|
||||
m.tolower = []int{}
|
||||
output := &URN{}
|
||||
|
||||
{
|
||||
m.cs = start
|
||||
}
|
||||
|
||||
{
|
||||
if (m.p) == (m.pe) {
|
||||
goto _testEof
|
||||
@@ -1674,7 +1672,6 @@ func (m *machine) Parse(input []byte) (*URN, error) {
|
||||
{
|
||||
goto st46
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+27
-13
@@ -1,18 +1,37 @@
|
||||
SHELL := /bin/bash
|
||||
RAGEL := ragel
|
||||
GOFMT := go fmt
|
||||
|
||||
export GO_TEST=env GOTRACEBACK=all go test $(GO_ARGS)
|
||||
|
||||
.PHONY: build
|
||||
build: machine.go
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
@rm -rf docs
|
||||
@rm -f machine.go
|
||||
|
||||
.PHONY: images
|
||||
images: docs/urn.png
|
||||
|
||||
.PHONY: removecomments
|
||||
removecomments:
|
||||
@cd ./tools/removecomments; go build -o ../../removecomments .
|
||||
|
||||
machine.go: machine.go.rl
|
||||
ragel -Z -G2 -e -o $@ $<
|
||||
@sed -i '/^\/\/line/d' $@
|
||||
@$(MAKE) -s file=$@ snake2camel
|
||||
@gofmt -w -s $@
|
||||
|
||||
machine.go: removecomments
|
||||
|
||||
machine.go:
|
||||
$(RAGEL) -Z -G2 -e -o $@ $<
|
||||
@./removecomments $@
|
||||
$(MAKE) -s file=$@ snake2camel
|
||||
$(GOFMT) $@
|
||||
|
||||
docs/urn.dot: machine.go.rl
|
||||
@mkdir -p docs
|
||||
ragel -Z -e -Vp $< -o $@
|
||||
$(RAGEL) -Z -e -Vp $< -o $@
|
||||
|
||||
docs/urn.png: docs/urn.dot
|
||||
dot $< -Tpng -o $@
|
||||
@@ -22,13 +41,8 @@ bench: *_test.go machine.go
|
||||
go test -bench=. -benchmem -benchtime=5s ./...
|
||||
|
||||
.PHONY: tests
|
||||
tests: *_test.go machine.go
|
||||
go test -race -timeout 10s -coverprofile=coverage.out -covermode=atomic -v ./...
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
@rm -rf docs
|
||||
@rm -f machine.go
|
||||
tests: *_test.go
|
||||
$(GO_TEST) ./...
|
||||
|
||||
.PHONY: snake2camel
|
||||
snake2camel:
|
||||
@@ -36,4 +50,4 @@ snake2camel:
|
||||
while ( match($$0, /(.*)([a-z]+[0-9]*)_([a-zA-Z0-9])(.*)/, cap) ) \
|
||||
$$0 = cap[1] cap[2] toupper(cap[3]) cap[4]; \
|
||||
print \
|
||||
}' $(file)
|
||||
}' $(file)
|
||||
|
||||
+23
@@ -1,9 +1,13 @@
|
||||
package urn
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const errInvalidURN = "invalid URN: %s"
|
||||
|
||||
// URN represents an Uniform Resource Name.
|
||||
//
|
||||
// The general form represented is:
|
||||
@@ -61,3 +65,22 @@ func Parse(u []byte) (*URN, bool) {
|
||||
|
||||
return urn, true
|
||||
}
|
||||
|
||||
// MarshalJSON marshals the URN to JSON string form (e.g. `"urn:oid:1.2.3.4"`).
|
||||
func (u URN) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(u.String())
|
||||
}
|
||||
|
||||
// MarshalJSON unmarshals a URN from JSON string form (e.g. `"urn:oid:1.2.3.4"`).
|
||||
func (u *URN) UnmarshalJSON(bytes []byte) error {
|
||||
var str string
|
||||
if err := json.Unmarshal(bytes, &str); err != nil {
|
||||
return err
|
||||
}
|
||||
if value, ok := Parse([]byte(str)); !ok {
|
||||
return fmt.Errorf(errInvalidURN, str)
|
||||
} else {
|
||||
*u = *value
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user