github.com/whyrusleeping/gx@v0.14.3/gxutil/lckfile.go (about)

     1  package gxutil
     2  
     3  import (
     4  	"encoding/json"
     5  	"fmt"
     6  	"os"
     7  )
     8  
     9  const LockVersion = 1
    10  
    11  type LockFile struct {
    12  	Lock
    13  	LockVersion int `json:"lockVersion"`
    14  }
    15  
    16  type Lock struct {
    17  	Language string `json:"language,omitempty"`
    18  
    19  	Ref  string                     `json:"ref,omitempty"`
    20  	Deps map[string]map[string]Lock `json:"deps,omitempty"`
    21  }
    22  
    23  func LoadLockFile(lck *LockFile, fname string) error {
    24  	fi, err := os.Open(fname)
    25  	if err != nil {
    26  		return err
    27  	}
    28  
    29  	if err := json.NewDecoder(fi).Decode(lck); err != nil {
    30  		return err
    31  	}
    32  
    33  	if lck.LockVersion != LockVersion {
    34  		return fmt.Errorf("unsupported lockfile version: %d", lck.LockVersion)
    35  	}
    36  
    37  	return nil
    38  }