-
Notifications
You must be signed in to change notification settings - Fork 0
/
resource.go
87 lines (73 loc) · 2.68 KB
/
resource.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*******************************************************************************
* Copyright (c) 2009-2023 Crater Dog Technologies™. All Rights Reserved. *
*******************************************************************************
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. *
* *
* This code is free software; you can redistribute it and/or modify it under *
* the terms of The MIT License (MIT), as published by the Open Source *
* Initiative. (See http://opensource.org/licenses/MIT) *
*******************************************************************************/
package elements
import (
fmt "fmt"
abs "github.com/bali-nebula/go-component-framework/abstractions"
uri "net/url"
)
// RESOURCE IMPLEMENTATION
// This constructor creates a new resource from the specified universal resource
// identifier (URI) string.
func ResourceFromString(string_ string) abs.ResourceLike {
var _, err = uri.Parse(string_)
if err != nil {
var message = fmt.Sprintf("Attempted to construct a resource from an invalid URI: %v", string_)
panic(message)
}
return Resource(string_)
}
// This constructor creates a new resource from the specified universal resource
// identifier (URI) pointer.
func ResourceFromURI(url *uri.URL) abs.ResourceLike {
return Resource(url.String())
}
// This type defines the methods associated with a web resource element that
// extends the native Go string type and represents the URI corresponding to
// that web resource.
type Resource string
// QUANTIZED INTERFACE
// This method returns a string value for this lexical element.
func (v Resource) AsString() string {
return string(v)
}
// SEGMENTED INTERFACE
// This method returns the scheme part of this resource element.
func (v Resource) GetScheme() string {
var u, _ = uri.Parse(string(v))
return u.Scheme
}
// This method returns the authority part of this resource element.
func (v Resource) GetAuthority() string {
var authority string
var u, _ = uri.Parse(string(v))
var user = u.User.String()
var host = u.Host
if len(user) > 0 {
authority = user + "@"
}
authority += host
return authority
}
// This method returns the path part of this resource element.
func (v Resource) GetPath() string {
var u, _ = uri.Parse(string(v))
return u.Path
}
// This method returns the query part of this resource element.
func (v Resource) GetQuery() string {
var u, _ = uri.Parse(string(v))
return u.RawQuery
}
// This method returns the fragment part of this resource element.
func (v Resource) GetFragment() string {
var u, _ = uri.Parse(string(v))
return u.Fragment
}