2019-10-22 23:01:37 +03:00
|
|
|
package parser
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"go/token"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
var _ Decl = HTTPDecl{}
|
|
|
|
|
|
|
|
type HTTPDecl struct {
|
|
|
|
file *File
|
|
|
|
pos token.Pos
|
|
|
|
value string
|
|
|
|
}
|
|
|
|
|
2019-10-23 20:19:39 +03:00
|
|
|
func (d HTTPDecl) String() string {
|
|
|
|
b, _ := json.Marshal(d)
|
|
|
|
return string(b)
|
|
|
|
}
|
|
|
|
|
2019-10-22 23:01:37 +03:00
|
|
|
func (d HTTPDecl) MarshalJSON() ([]byte, error) {
|
|
|
|
return json.Marshal(map[string]interface{}{
|
2019-10-25 16:30:31 +03:00
|
|
|
"type": "pkger.Dir",
|
2019-10-22 23:01:37 +03:00
|
|
|
"file": d.file,
|
|
|
|
"pos": d.pos,
|
|
|
|
"value": d.value,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d HTTPDecl) File() (*File, error) {
|
|
|
|
if d.file == nil {
|
|
|
|
return nil, os.ErrNotExist
|
|
|
|
}
|
|
|
|
return d.file, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d HTTPDecl) Pos() (token.Pos, error) {
|
|
|
|
if d.pos <= 0 {
|
|
|
|
return -1, os.ErrNotExist
|
|
|
|
}
|
|
|
|
return d.pos, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d HTTPDecl) Value() (string, error) {
|
|
|
|
if d.value == "" {
|
|
|
|
return "", os.ErrNotExist
|
|
|
|
}
|
|
|
|
return d.value, nil
|
|
|
|
}
|
|
|
|
|
2019-10-23 20:19:39 +03:00
|
|
|
func (d HTTPDecl) Files(virtual map[string]string) ([]*File, error) {
|
|
|
|
od := OpenDecl{
|
|
|
|
file: d.file,
|
|
|
|
pos: d.pos,
|
|
|
|
value: d.value,
|
2019-10-22 23:01:37 +03:00
|
|
|
}
|
2019-10-23 20:19:39 +03:00
|
|
|
return od.Files(virtual)
|
2019-10-22 23:01:37 +03:00
|
|
|
}
|