github.com/bingoohuang/pkger@v0.0.0-20210127185155-a71b9df4c4c7/parser/mkdir.go (about)

     1  package parser
     2  
     3  import (
     4  	"encoding/json"
     5  	"go/token"
     6  	"os"
     7  )
     8  
     9  var _ Decl = MkdirAllDecl{}
    10  
    11  type MkdirAllDecl struct {
    12  	file  *File
    13  	pos   token.Position
    14  	value string
    15  }
    16  
    17  func (d MkdirAllDecl) String() string {
    18  	b, _ := json.Marshal(d)
    19  	return string(b)
    20  }
    21  
    22  func (d MkdirAllDecl) MarshalJSON() ([]byte, error) {
    23  	return json.Marshal(map[string]interface{}{
    24  		"type":  "pkger.MkdirAll",
    25  		"file":  d.file,
    26  		"pos":   d.pos,
    27  		"value": d.value,
    28  	})
    29  }
    30  
    31  func (d MkdirAllDecl) File() (*File, error) {
    32  	if d.file == nil {
    33  		return nil, os.ErrNotExist
    34  	}
    35  	return d.file, nil
    36  }
    37  
    38  func (d MkdirAllDecl) Position() (token.Position, error) {
    39  	return d.pos, nil
    40  }
    41  
    42  func (d MkdirAllDecl) Value() (string, error) {
    43  	if d.value == "" {
    44  		return "", os.ErrNotExist
    45  	}
    46  	return d.value, nil
    47  }
    48  
    49  func (d MkdirAllDecl) VirtualPaths() []string {
    50  	return []string{d.value}
    51  }