code.oscarkilo.com/klex-git/commit/main.go

..
main.go
package main

// This binary is executed during a commit to the client Git repo.
// It figures out which files the commit affects, and then makes
// the appropriate calls to Klex.

import (
  "log"

  "oscarkilo.com/klex-git/api"
  "oscarkilo.com/klex-git/config"
  "oscarkilo.com/klex-git/plan"
  "oscarkilo.com/klex-git/util"
)

func main() {
  log.SetFlags(log.LstdFlags | log.Lshortfile)
  log.SetPrefix("klex-git: ")

  err := util.CdRoot()
  if err != nil {
    panic(err)
  }

  config, err := config.ReadConfig()
  if err != nil {
    panic(err)
  }

  commit, err := util.GetCommitInfo()
  if err != nil {
    panic(err)
  }

  client := api.NewClient(config.KlexUrl, config.ApiKey)
  log.Printf("handling %s\n", commit.DebugString())
  plan := plan.NewPlan(config, commit, client)
  log.Printf("plan:\n%s\n", plan.DebugString())

  for _, ds := range plan.ChangedDatasets {
    err = plan.UploadDataset2(ds)
    if err != nil {
      panic(err)
    }
    log.Printf("uploaded dataset: %s\n", ds)
  }
}