github.com/motyar/up@v0.2.10/config/hooks.go (about)

     1  package config
     2  
     3  import (
     4  	"encoding/json"
     5  	"errors"
     6  )
     7  
     8  // Hooks for the project.
     9  type Hooks struct {
    10  	Build Hook `json:"build"`
    11  	Clean Hook `json:"clean"`
    12  }
    13  
    14  // Hook is one or more commands.
    15  type Hook []string
    16  
    17  // UnmarshalJSON implementation.
    18  func (h *Hook) UnmarshalJSON(b []byte) error {
    19  	switch b[0] {
    20  	case '"':
    21  		var s string
    22  		if err := json.Unmarshal(b, &s); err != nil {
    23  			return err
    24  		}
    25  		*h = append(*h, s)
    26  		return nil
    27  	case '[':
    28  		return json.Unmarshal(b, (*[]string)(h))
    29  	default:
    30  		return errors.New("hook must be a string or array of strings")
    31  	}
    32  }
    33  
    34  // IsEmpty returns true if the hook is empty.
    35  func (h *Hook) IsEmpty() bool {
    36  	return h == nil || len(*h) == 0
    37  }