diff --git a/core.go b/core.go new file mode 100644 index 0000000..fe56534 --- /dev/null +++ b/core.go @@ -0,0 +1,137 @@ +package cvdata + +import ( + "fmt" + + utils "github.com/jesusperez/datautils" +) + +type ProfileType struct { + Auth AuthInfoType `yaml:"auth" json:"auth"` + Desc string `yaml:"desc" json:"desc"` +} +type CoreProfile struct { + CoreProfile []ProfileType `yaml:"profile" json:"profile"` +} +type SkillsType struct { + Id string `yaml:"id" json:"id"` + Auth AuthInfoType `yaml:"auth" json:"auth"` + Title string `yaml:"title" json:"title"` + Max int `yaml:"max" json:"max"` + Value int `yaml:"value" json:"value"` +} +type CertificationType struct { + Id string `yaml:"id" json:"id"` + Auth AuthInfoType `yaml:"auth" json:"auth"` + Title string `yaml:"title" json:"title"` + Author string `yaml:"author" json:"author"` + Date string `yaml:"date" json:"date"` + Link string `yaml:"link" json:"link"` + Href string `yaml:"href" json:"href"` + Certid string `yaml:"certid" json:"certid"` +} +type SitesType struct { + Id string `yaml:"id" json:"id"` + Auth AuthInfoType `yaml:"auth" json:"auth"` + Title string `yaml:"title" json:"title"` + Sub string `yaml:"sub" json:"sub"` + Link string `yaml:"link" json:"link"` + Type string `yaml:"type" json:"type"` + Alt string `yaml:"alt" json:"alt"` + Img string `yaml:"img" json:"img"` +} +type Sites struct { + Sites []SitesType `yaml:"sites" json:"sites"` +} +type LangsType struct { + Id string `yaml:"id" json:"id"` + Title string `yaml:"title" json:"title"` + Mode string `yaml:"mode" json:"mode"` +} +type Langs struct { + Langs []LangsType `yaml:"langs" json:"langs"` +} +type MissionHowType struct { + Auth AuthInfoType `yaml:"auth" json:"auth"` + Desc string `yaml:"desc" json:"desc"` +} +type DataCoreType struct { + Name string `yaml:"name" json:"name"` + Fullname string `yaml:"fullname" json:"fullname"` + Title1 string `yaml:"title1" json:"title1"` + Title2 string `yaml:"title2" json:"title2"` + Imgalt string `yaml:"imgalt" json:"imgalt"` + Imgsrc string `yaml:"imgsrc" json:"imgsrc"` + Email string `yaml:"email" json:"email"` + Phone string `yaml:"phone" json:"phone"` + Address string `yaml:"address" json:"address"` + Postalcode string `yaml:"postalcode" json:"postalcode"` + State string `yaml:"state" json:"state"` + City string `yaml:"city" json:"city"` + Country string `yaml:"country" json:"country"` + Birthdate string `yaml:"birthdate" json:"birthdate"` + Status string `yaml:"status" json:"status"` + Mission string `yaml:"mission" json:"mission"` + Mission_how []MissionHowType `yaml:"mission_how" json:"mission_how"` + Profile []ProfileType `yaml:"profile" json:"profile"` + Certifications []CertificationType `yaml:"certifications" json:"certifications"` + Skills []SkillsType `yaml:"skills" json:"skills"` + Infra []SkillsType `yaml:"infra" json:"infra"` + Sites []SitesType `yaml:"sites" json:"sites"` + Langs []LangsType `yaml:"langs" json:"langs"` +} +type DataCore struct { + Core DataCoreType `yaml:"core" json:"core"` +} +type DataLangCoreType struct { + Title1 string `yaml:"title1" json:"title1"` + Title2 string `yaml:"title2" json:"title2"` + Imgalt string `yaml:"imgalt" json:"imgalt"` + State string `yaml:"state" json:"state"` + City string `yaml:"city" json:"city"` + Country string `yaml:"country" json:"country"` + Status string `yaml:"status" json:"status"` + Mission string `yaml:"mission" json:"mission"` + Mission_how []MissionHowType `yaml:"mission_how" json:"mission_how"` + Profile []ProfileType `yaml:"profile" json:"profile"` + Certifications []CertificationType `yaml:"certifications" json:"certifications"` +} +type DataLangCore struct { + Core DataLangCoreType `yaml:"core" json:"core"` +} +func (profileData *CoreProfile)Load(path string) ([]ProfileType, error) { + d,file,errpath := utils.DecoderFromFile(path) + if errpath != nil { + return profileData.CoreProfile, errpath + } + defer file.Close() + if err := d.Decode(&profileData); err != nil { + fmt.Printf("Decode: %v", err) + return profileData.CoreProfile, err + } + return profileData.CoreProfile, nil +} +func (datacore *DataCore)Load(path string) (DataCoreType, error) { + d,file,errpath := utils.DecoderFromFile(path) + if errpath != nil { + return datacore.Core, errpath + } + defer file.Close() + if err := d.Decode(&datacore); err != nil { + fmt.Printf("Decode: %v", err) + return datacore.Core, err + } + return datacore.Core, nil +} +func(datalangcore *DataLangCore)Load(path string) (DataLangCoreType, error) { + d,file,errpath := utils.DecoderFromFile(path) + if errpath != nil { + return datalangcore.Core, errpath + } + defer file.Close() + if err := d.Decode(&datalangcore); err != nil { + fmt.Printf("Decode: %v", err) + return datalangcore.Core, err + } + return datalangcore.Core, nil +} diff --git a/cv.go b/cv.go new file mode 100644 index 0000000..841e9eb --- /dev/null +++ b/cv.go @@ -0,0 +1,465 @@ +package cvdata + +import ( + "encoding/json" + "fmt" + "os/exec" + "path/filepath" + + // "github.com/jesusperez/srvcvgen" + cfg "github.com/jesusperez/cfgsrv" + utils "github.com/jesusperez/datautils" + "gopkg.in/yaml.v3" +) + +// type TemplateItem struct { +// Path string `yaml:"path"` +// Route string `yaml:"route"` +// } +// type Config struct { +// UsersPath string `yaml:"usersPath"` +// ModelsPath string `yaml:"modelsPath"` +// LogOut string `yaml:"logOut"` +// RequestOut string `yaml:"RequestOut"` +// Host string `yaml:"host"` +// Port int `yaml:"port"` +// Protocol string `yaml:"protocol"` +// KeyPem string `yaml:"keyPem"` +// CertPem string `yaml:"certPem"` +// AllowOrigin []string `yaml:"allowOrigin"` +// UseJWT bool `yaml:"useJWT"` +// UseAuthz bool `yaml:"useAuthz"` +// AauthzModel string `yaml:"rbacModel"` +// AuthzPolicy string `yaml:"rbacPolicy"` +// RouteRoot string `yaml:"routeRoot"` +// RouteGetPage string `yaml:"routeGetPage"` +// RouteGetPageParam string `yaml:"routeGetPageParam"` +// RouteGetData string `yaml:"routeGetData"` +// RouteGetDataParam string `yaml:"routeGetDataParam"` +// RoutePostData string `yaml:"routePostData"` +// TemplatesRoot string `yaml:"templatesRoot"` +// TemplatesExt string `yaml:"templatesExt"` +// TemplatesIncludes string `yaml:"templatesIncludes"` +// TemplatesLayouts string `yaml:"templatesLayouts"` +// TemplatesFiles map[string]TemplateItem `yaml:"templatesFiles"` +// AssetsPath string `yaml:"assetsPath"` +// AssetsURL string `yaml:"assetsURL"` +// DataDistPath string `yaml:"dataDistPath"` +// DataPath string `yaml:"dataPath"` +// DataCorePath string `yaml:"dataCorePath"` +// DataDflt string `yaml:"dataDflt"` +// DataItems []string `yaml:"dataItems"` +// MainLang string `yaml:"mainLang"` +// Langs []string `yaml:"langs"` +// DebugLevel int `yaml:"debugLevel"` +// UseRepo bool `yaml:"useRepo"` +// RepoPath string `yaml:"repoPath"` +// RepoName string `yaml:"repoName"` +// RepoCommit string `yaml:"repoCommit"` +// QuietGit bool `yaml:"quietGit"` +// } + +type AuthInfoType struct { + Editable bool `yaml:"editable" json:"editable"` + Viewchange bool `yaml:"viewchange" json:"viewchange"` + Show bool `yaml:"show" json:"show"` +} +type ShowInfoType struct { + Id string `yaml:"id" json:"id"` + Ky string `yaml:"ky" json:"ky"` + Write bool `yaml:"write" json:"write"` + Change bool `yaml:"change" json:"change"` + Admin bool `yaml:"admin" json:"admin"` + // Save bool `yaml:"save" json:"save"` + Auth AuthInfoType `yaml:"auth" json:"auth"` + Fullname bool `yaml:"fullname" json:"fullname"` + Personal bool `yaml:"personal" json:"personal"` + Title bool `yaml:"title" json:"title"` + Image bool `yaml:"image" json:"image"` + Mission bool `yaml:"mission" json:"mission"` + Mission_how bool `yaml:"mission_how" json:"mission_how"` + Phone bool `yaml:"phone" json:"phone"` + Address bool `yaml:"address" json:"address"` + Status bool `yaml:"status" json:"status"` + Birthdate bool `yaml:"birthday" json:"birthdate"` + Sites bool `yaml:"sites" json:"sites"` + Skills bool `yaml:"skills" json:"skills"` + Skills_itms bool `yaml:"skills_itms" json:"skills_itms"` + Infra bool `yaml:"infra" json:"infra"` + Certs bool `yaml:"certs" json:"certs"` + Langs bool `yaml:"langs" json:"langs"` + Profile bool `yaml:"profile" json:"profile"` + Work_experience_itms bool `yaml:"work_experience_itms" json:"work_experience_itms"` + Work_experience ShowWorkExperienceType `yaml:"work_experience" json:"work_experience"` + Projects_itms bool `yaml:"projects_itms" json:"projects_itms"` + Projects ShowProjectType `yaml:"projects" json:"projects"` + Education_itms bool `yaml:"education_itms" json:"education_itms"` + Education ShowEducationType `yaml:"education" json:"education"` + Talks_itms bool `yaml:"talks_itms" json:"talks_itms"` + Talks ShowTalksType `yaml:"talks" json:"talks"` + Teaching_itms bool `yaml:"teaching_itms" json:"teaching_itms"` + Teaching ShowTeachingType `yaml:"teaching" json:"teaching"` + Others_itms bool `yaml:"others_itms" json:"others_itms"` + Others bool `yaml:"others" json:"others"` +} +type ModelType struct { + Id string `yaml:"id" json:"id"` + Title string `yaml:"title" json:"title"` + Path string `yaml:"path" json:"path"` +} +type Models struct { + Models []ModelType `yaml:"models" json:"models"` +} +type CVData struct { + Models []ModelType `yaml:"models" json:"models"` + Showinfo []ShowInfoType `yaml:"showinfo" json:"showinfo"` + Core DataCoreType `yaml:"core" json:"core"` + CoreLang DataLangCoreType `yaml:"corelang" json:"corelang"` + Projects []ProjectType `yaml:"projects" json:"projects"` + Work_experience []WorkExperienceType `yaml:"work_experience" json:"work_experience"` + Education []EducationType `yaml:"education" json:"education"` + Talks []TalksType `yaml:"talks" json:"talks" json:""` + Teaching []TeachingType `yaml:"teaching" json:"teaching"` + Others []OtherType `yaml:"others" json:"others"` +} +type CVLangData map[string]CVData +// struct { +// lang string `yaml:"lang" json:"lang"` +// Data CVData `yaml:"data" json:"data"` +// } +type CVModelData map[string]CVLangData +// type CVModelData struct { +// Id string `yaml:"id" json:"id"` +// Data CVLangData `yaml:"data" json:"data"` +// } +type DataCVgen struct { + Data CVLangData `yaml:"data" json:"data"` + Models []ModelType `yaml:"models" json:"models"` +} +type CVPostData struct { + U string `yaml:"u" json:"u"` + Data CVModelData `yaml:"data" json:"data"` +} +func (models *Models)Load(path string) ([]ModelType, error) { + d,file,errpath := utils.DecoderFromFile(path) + if errpath != nil { + return models.Models, errpath + } + defer file.Close() + if err := d.Decode(&models); err != nil { + fmt.Printf("Decode: %v\n", err) + return models.Models, err + } + return models.Models, nil +} + +func (cvdata *CVData)Load(root_path string, lang string, config *cfg.Config) error { + //err := *new(error) + var err error + for _,itm := range config.DataItems { + itmpath := fmt.Sprintf("%s/%s.yaml",root_path,itm) + if itm == "showinfo" { + itmpath = fmt.Sprintf("%s/%s",root_path,itm) + } + if !utils.ExistsPath(itmpath) { + continue + } + switch itm { + case "showinfo": + cvdata.Showinfo, err = loadShowData(itmpath) + case "core": + if lang == "" { + var datacore DataCore + cvdata.Core, err = datacore.Load(itmpath) + } else { + var datalangcore DataLangCore + cvdata.CoreLang, err = datalangcore.Load(itmpath) + } + case "profile": + var profile CoreProfile + cvdata.Core.Profile, err = profile.Load(itmpath) + case "projects": + var projects Projects + cvdata.Projects, err = projects.Load(itmpath) + case "work_experience": + var work_experience WorkExperience + cvdata.Work_experience, err = work_experience.Load(itmpath) + case "education": + var education Education + cvdata.Education, err = education.Load(itmpath) + case "teaching": + var teaching Teaching + cvdata.Teaching, err = teaching.Load(itmpath) + case "talks": + var talks Talks + cvdata.Talks, err = talks.Load(itmpath) + case "others": + var others Others + cvdata.Others, err = others.Load(itmpath) + case "models": + var models Models + cvdata.Models, err = models.Load(itmpath) + default: + fmt.Printf("cvdata: %s not implemented yet\n",itm) + continue + } + if err != nil && lang == "" { + fmt.Printf("Error load cv %s: %v\n", itm, err) + } + } + return nil +} +func (cvdata *CVData)Write(ky string, path string, config *cfg.Config) error { + for _,itm := range config.DataItems { + var data []byte + var err error + switch itm { + case "showinfo": + if cvdata.Showinfo == nil { + continue + } + var showinfodata []ShowInfoType + showinfodata = cvdata.Showinfo + for _,showitm := range showinfodata { + showitmdata := [1]ShowInfoType{showitm} + data, err := yaml.Marshal(showitmdata) + if err != nil { + fmt.Printf("Error Parse cv %s (%s): %v\n", itm, showitm.Id, err) + } else { + if err := utils.CheckDirPath(fmt.Sprintf("%s/showinfo",path)) ; err == nil { + if res := utils.WriteData(string(data),fmt.Sprintf("%s/showinfo/%s.yaml",path,showitm.Id)) ; res != nil { + fmt.Printf("Error write cv %s: %v\n", itm, err) + } + } + } + } + continue + case "core": + if ky == "main" { + if len(cvdata.Core.Title1) > 0 { + var coredata DataCore + coredata.Core = cvdata.Core + data, err = yaml.Marshal(coredata) + } + } else { + if len(cvdata.CoreLang.Title1) > 0 { + var corelangdata DataLangCore + corelangdata.Core = cvdata.CoreLang + data, err = yaml.Marshal(corelangdata) + } + } + case "profile": + if ky == "main" { + if cvdata.Core.Profile != nil { + var profiledata CoreProfile + profiledata.CoreProfile = cvdata.Core.Profile + data, err = yaml.Marshal(profiledata) + } + } else { + if cvdata.CoreLang.Profile != nil { + var profiledata CoreProfile + profiledata.CoreProfile = cvdata.CoreLang.Profile + data, err = yaml.Marshal(profiledata) + } + } + case "projects": + if cvdata.Projects == nil { + continue + } + var projectsdata Projects + projectsdata.Projects = cvdata.Projects + data, err = yaml.Marshal(projectsdata) + case "work_experience": + if cvdata.Work_experience == nil { + } + var experience WorkExperience + experience.WorkExperience = cvdata.Work_experience + data, err = yaml.Marshal(experience) + case "education": + if cvdata.Education == nil { + continue + } + var educationdata Education + educationdata.Education = cvdata.Education + data, err = yaml.Marshal(educationdata) + case "teaching": + if cvdata.Teaching == nil { + continue + } + var teachingdata Teaching + teachingdata.Teaching = cvdata.Teaching + data, err = yaml.Marshal(teachingdata) + case "talks": + if cvdata.Talks == nil { + continue + } + var talksdata Talks + talksdata.Talks = cvdata.Talks + data, err = yaml.Marshal(talksdata) + case "others": + if cvdata.Others == nil { + continue + } + var othersdata Others + othersdata.Others = cvdata.Others + data, err = yaml.Marshal(othersdata) + case "models": + if cvdata.Models == nil { + continue + } + var modelsdata Models + modelsdata.Models = cvdata.Models + data, err = yaml.Marshal(modelsdata) + default: + fmt.Printf("cvdata: %s not implemented yet\n",itm) + continue + } + if len(data) == 0 { + continue + } + if err != nil { + fmt.Printf("Error Parse cv %s: %v\n", itm, err) + } else { + if res := utils.WriteData(string(data),fmt.Sprintf("%s/%s.yaml",path,itm)) ; res != nil { + fmt.Printf("Error write cv %s: %v\n", itm, err) + // } else if config.UseRepo && config.RepoPath != "" { + // pathfile :=fmt.Sprintf("%s/%s.yaml",strings.Replace(path,fmt.Sprintf("%s/",config.DataPath),"",1),itm) + // if errgit := gitCommit(config.RepoPath, pathfile, fmt.Sprintf("'%s'",config.RepoCommit),config.RepoName,config.RepoAuthName, config.RepoAuthEmail, time.Now()); errgit != nil { + // fmt.Printf("Error git commit cv %s: %v\n", pathfile, err) + // } + } + } + } + return nil +} +func (cvmodel CVModelData)Write(config *cfg.Config) ([]string,error) { + var keys []string + root_path := config.DataPath + for key,mdl := range cvmodel { + keys = append(keys,fmt.Sprintf("%s:",key)) + // root_path with YAML file exists ? + path := fmt.Sprintf("%s/%s",root_path,key) + //fmt.Printf("path: %+v\n", path) + if err := utils.CheckDirPath(path) ; err != nil { + fmt.Printf("Error create %s: %v\n",path, err) + return keys, err + } + langpath := fmt.Sprintf("%s/langs",path) + if err := utils.CheckDirPath(langpath) ; err != nil { + fmt.Printf("Error create %s: %v\n",langpath, err) + return keys,err + } + for kylng,cvdata := range mdl { + keys = append(keys,kylng) + if kylng == "main" { + if res := cvdata.Write(kylng,path,config) ; res != nil { + fmt.Printf("Error write %s: %v\n",path, res) + return keys,res + } + } else { + langitempath := fmt.Sprintf("%s/%s",langpath,kylng) + if err := utils.CheckDirPath(langitempath) ; err != nil { + fmt.Printf("Error create %s: %v\n",langitempath, err) + return keys,err + } + if res := cvdata.Write(kylng,langitempath,config); res != nil { + fmt.Printf("Error write %s: %v\n",langitempath, res) + return keys,res + } + } + } + if config.GenDist { + data, err := json.Marshal(cvmodel) + if err != nil { + fmt.Printf("Error Parse cv %s: %v\n",key, err) + } else { + err := utils.CheckDirPath(fmt.Sprintf("%s",config.DataDistPath)) + if err == nil { + path := fmt.Sprintf("%s/%s.json",config.DataDistPath,key) + if res := utils.WriteData(string(data),path) ; res != nil { + fmt.Printf("Error write cv %s: %v\n", key, err) + } else { + fmt.Printf("CV %s writed to: %s\n", key,path) + } + } + } + } + if config.UseRepo && config.RepoPath != "" { + var cmd *exec.Cmd + var errgit error + if cmd,_,errgit = utils.GitCommit(config.RepoPath,key,config.RepoCommit,config.RepoName,config.BackgGit,config.QuietGit); errgit != nil { + fmt.Printf("Error git commit cv %s: %v\n", config.RepoPath, errgit) + } + if errgit == nil && config.BackgGit { + if errgit = cmd.Wait(); errgit != nil { + fmt.Printf("Error pull %s (%s): %v\n", config.RepoPath, config.RepoName,errgit) + } + } + } + } + return keys,nil +} +func loadShowInfoItem(path string) (ShowInfoType, error) { + var showinfo []ShowInfoType + d,file,errpath := utils.DecoderFromFile(path) + if errpath != nil { + return ShowInfoType{}, errpath + } + defer file.Close() + if err := d.Decode(&showinfo); err != nil { + fmt.Printf("Decode: %v", err) + return ShowInfoType{},err + } + return showinfo[0], nil +} +func loadShowData(path string) ([]ShowInfoType, error) { + var showData []ShowInfoType + files, err := filepath.Glob(fmt.Sprintf("%s/*.yaml",path)) + if err != nil { + fmt.Printf("showinfo: %v", err) + return showData,err + } + for _, file := range files { + data,err := loadShowInfoItem(file) + if err == nil { + showData = append(showData,data) + } + // fmt.Println(file) + } + return showData,nil +} +func LoadCVData(root_path string, config *cfg.Config, useRepo bool) (DataCVgen, error) { + var errgit error + var cmd *exec.Cmd + if useRepo && config.UseRepo && config.RepoPath != "" { + if cmd,errgit = utils.GitPull(config.RepoPath,config.RepoName,config.BackgGit,config.QuietGit); errgit != nil { + fmt.Printf("Error pull %s (%s): %v\n", config.RepoPath, config.RepoName,errgit) + } + } + var datacvgen DataCVgen + cvlangdata := make(map[string]CVData,2) + var data CVData + var models Models + mdls, _ := models.Load(fmt.Sprintf("%s/%s",config.DataPath,config.DataModelsRoot)) + datacvgen.Models = mdls + if err := data.Load(root_path,"",config); err == nil { + cvlangdata["main"] = data + } + for _,lng := range config.Langs { + if lng != config.MainLang { + path := fmt.Sprintf("%s/langs/%s",root_path,lng) + var data CVData + if err := data.Load(path,lng,config) ; err == nil { + cvlangdata[lng] = data + } + } + } + datacvgen.Data = cvlangdata + if useRepo && config.UseRepo && config.RepoPath != "" && errgit == nil && config.BackgGit { + fmt.Printf("End pull %s (%s)\n", config.RepoPath, config.RepoName) + if errgit = cmd.Wait(); errgit != nil { + fmt.Printf("Error pull %s (%s): %v\n", config.RepoPath, config.RepoName,errgit) + } + } + return datacvgen, nil +} diff --git a/datalang.go b/datalang.go new file mode 100644 index 0000000..85d4b84 --- /dev/null +++ b/datalang.go @@ -0,0 +1,40 @@ +package cvdata + +import ( + "fmt" + + utils "github.com/jesusperez/datautils" +) + +type DataLangType struct { + Imgalt string `yaml:"imgalt" json:"imgalt"` + Title1 string `yaml:"title1" json:"title1"` + Title2 string `yaml:"title2" json:"title2"` + Country string `yaml:"country" json:"country"` + Birthdate string `yaml:"birthdate" json:"birthdate"` + Status string `yaml:"status" json:"status"` + Mission string `yaml:"mission" json:"mission"` + Mission_how []MissionHowType `yaml:"mission_how" json:"mission_how"` + Profile []ProfileType `yaml:"profile" json:"profile"` + Certifications []CertificationType `yaml:"certifications" json:"certifications"` + Work_experiences []WorkExperienceType `yaml:"work_experiences" json:"work_experiences"` + Projects []ProjectType `yaml:"projects" json:"projects"` + Education []EducationType `yaml:"education" json:"education"` + Talks []TalksType `yaml:"talks" json:"talks"` + Teaching []TeachingType `yaml:"teaching" json:"teaching"` + Others []OtherType `yaml:"others" json:"others"` +} + +func loadDataLang(path string) (*DataLangType, error) { + datalang := &DataLangType{} + d,file,errpath := utils.DecoderFromFile(path) + if errpath != nil { + return nil, errpath + } + defer file.Close() + if err := d.Decode(&datalang); err != nil { + fmt.Printf("Decode: %v", err) + return nil, err + } + return datalang, nil +} diff --git a/education.go b/education.go new file mode 100644 index 0000000..bdda15c --- /dev/null +++ b/education.go @@ -0,0 +1,43 @@ +package cvdata + +import ( + "fmt" + + utils "github.com/jesusperez/datautils" +) + +type EducationType struct { + Auth AuthInfoType `yaml:"auth" json:"auth"` + Date string `yaml:"date" json:"date"` + Title string `yaml:"title" json:"title"` + Org string `yaml:"org" json:"org"` + Location string `yaml:"location" json:"location"` + Cert string `yaml:"cert" json:"cert"` + Description []string `yaml:"description" json:"description"` + Tools []string `yaml:"tools" json:"tools"` +} +type Education struct { + Education []EducationType `yaml:"education" json:"education"` +} +type ShowEducationType struct { + Auth AuthInfoType `yaml:"auth" json:"auth"` + Date bool `yaml:"date" json:"date"` + Title bool `yaml:"title" json:"title"` + Org bool `yaml:"org" json:"org"` + Location bool `yaml:"location" json:"location"` + Cert bool `yaml:"cert" json:"cert"` + Description bool `yaml:"description" json:"description"` + Tools bool `yaml:"tools" json:"tools"` +} +func (education *Education)Load(path string) ([]EducationType, error) { + d,file,errpath := utils.DecoderFromFile(path) + if errpath != nil { + return education.Education, errpath + } + defer file.Close() + if err := d.Decode(&education); err != nil { + fmt.Printf("Decode: %v", err) + return education.Education, err + } + return education.Education, nil +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..fd7b280 --- /dev/null +++ b/go.mod @@ -0,0 +1,16 @@ +module cvdata + +go 1.17 + +replace github.com/jesusperez/cfgsrv => ../cfgsrv + +replace github.com/jesusperez/datautils => ../datautils + +replace github.com/jesusperez/srvcvgen => ../srvcvgen + +require gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b + +require ( + github.com/jesusperez/cfgsrv v0.0.0-00010101000000-000000000000 // indirect + github.com/jesusperez/datautils v0.0.0-00010101000000-000000000000 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..e387ff0 --- /dev/null +++ b/go.sum @@ -0,0 +1,4 @@ +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= +gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/others.go b/others.go new file mode 100644 index 0000000..a772886 --- /dev/null +++ b/others.go @@ -0,0 +1,26 @@ +package cvdata + +import ( + "fmt" + + utils "github.com/jesusperez/datautils" +) +type OtherType struct { + Auth AuthInfoType `yaml:"auth" json:"auth"` + Desc string `yaml:"desc" json:"desc"` +} +type Others struct { + Others []OtherType `yaml:"others" json:"others"` +} +func (others *Others)Load(path string) ([]OtherType, error) { + d,file,errpath := utils.DecoderFromFile(path) + if errpath != nil { + return others.Others, errpath + } + defer file.Close() + if err := d.Decode(&others); err != nil { + fmt.Printf("Decode: %v", err) + return others.Others, err + } + return others.Others, nil +} diff --git a/projects.go b/projects.go new file mode 100644 index 0000000..1fe6f0a --- /dev/null +++ b/projects.go @@ -0,0 +1,60 @@ +package cvdata + +import ( + "fmt" + + utils "github.com/jesusperez/datautils" +) + +type ProjectType struct { + Auth AuthInfoType `yaml:"auth" json:"auth"` + Date string `yaml:"date" json:"date"` + Name string `yaml:"name" json:"name"` + Title string `yaml:"title" json:"title"` + Img string `yaml:"img" json:"img"` + Site string `yaml:"site" json:"site"` + Code string `yaml:"code" json:"code"` + Purpose string `yaml:"purpose" json:"purpose"` + For string `yaml:"for" json:"for"` + Position string `yaml:"position" json:"position"` + License string `yaml:"license" json:"license"` + Demo string `yaml:"demo" json:"demo"` + Capture string `yaml:"capture" json:"capture"` + Description string `yaml:"description" json:"description"` + Features []string `yaml:"features" json:"features"` + Builtwith []string `yaml:"builtwith" json:"builtwith"` +} +type Projects struct { + Projects []ProjectType `yaml:"projects" json:"projects"` +} +type ShowProjectType struct { + Auth AuthInfoType `yaml:"auth" json:"auth"` + Name bool `yaml:"name" json:"name"` + Title bool `yaml:"title" json:"title"` + Img bool `yaml:"img" json:"img"` + Purpose bool `yaml:"purpose" json:"purpose"` + Site bool `yaml:"site" json:"site"` + Code bool `yaml:"code" json:"code"` + Date bool `yaml:"date" json:"date"` + For bool `yaml:"for" json:"for"` + Position bool `yaml:"position" json:"position"` + License bool `yaml:"license" json:"license"` + Demo bool `yaml:"demo" json:"demo"` + Capture bool `yaml:"capture" json:"capture"` + Description bool `yaml:"description" json:"description"` + Features bool `yaml:"features" json:"features"` + Builtwith bool `yaml:"builtwith" json:"builtwith"` +} + +func (projects *Projects)Load(path string) ([]ProjectType, error) { + d,file,errpath := utils.DecoderFromFile(path) + if errpath != nil { + return projects.Projects, errpath + } + defer file.Close() + if err := d.Decode(&projects); err != nil { + fmt.Printf("Decode: %v", err) + return projects.Projects, err + } + return projects.Projects, nil +} diff --git a/talks.go b/talks.go new file mode 100644 index 0000000..5a02c60 --- /dev/null +++ b/talks.go @@ -0,0 +1,41 @@ +package cvdata + +import ( + "fmt" + + utils "github.com/jesusperez/datautils" +) + +type TalksType struct { + Auth AuthInfoType `yaml:"auth" json:"auth"` + Date string `yaml:"date" json:"date"` + Title string `yaml:"title" json:"title"` + Org string `yaml:"org" json:"org"` + Location string `yaml:"location" json:"location"` + Description []string `yaml:"description" json:"description"` +} +type Talks struct { + Talks []TalksType `yaml:"talks" json:"talks"` +} + +type ShowTalksType struct { + Auth AuthInfoType `yaml:"auth" json:"auth"` + Date bool `yaml:"date" json:"date"` + Title bool `yaml:"title" json:"title"` + Org bool `yaml:"org" json:"org"` + Location bool `yaml:"location" json:"location"` + Description bool `yaml:"description" json:"description"` +} + +func (talks *Talks)Load(path string) ([]TalksType, error) { + d,file,errpath := utils.DecoderFromFile(path) + if errpath != nil { + return talks.Talks, errpath + } + defer file.Close() + if err := d.Decode(&talks); err != nil { + fmt.Printf("Decode: %v", err) + return talks.Talks, err + } + return talks.Talks, nil +} diff --git a/teaching.go b/teaching.go new file mode 100644 index 0000000..b51bb43 --- /dev/null +++ b/teaching.go @@ -0,0 +1,41 @@ +package cvdata + +import ( + "fmt" + + utils "github.com/jesusperez/datautils" +) + +type TeachingType struct { + Auth AuthInfoType `yaml:"auth" json:"auth"` + Date string `yaml:"date" json:"date"` + Title string `yaml:"title" json:"title"` + Org string `yaml:"org" json:"org"` + Location string `yaml:"location" json:"location"` + Description []string `yaml:"description" json:"description"` +} +type Teaching struct { + Teaching []TeachingType `yaml:"teaching" json:"teaching"` +} + +type ShowTeachingType struct { + Auth AuthInfoType `yaml:"auth" json:"auth"` + Date bool `yaml:"date" json:"date"` + Title bool `yaml:"title" json:"title"` + Org bool `yaml:"org" json:"org"` + Location bool `yaml:"location" json:"location"` + Description bool `yaml:"description" json:"description"` +} + +func (teaching *Teaching)Load(path string) ([]TeachingType, error) { + d,file,errpath := utils.DecoderFromFile(path) + if errpath != nil { + return teaching.Teaching, errpath + } + defer file.Close() + if err := d.Decode(&teaching); err != nil { + fmt.Printf("Decode: %v", err) + return teaching.Teaching, err + } + return teaching.Teaching, nil +} diff --git a/work_experience.go b/work_experience.go new file mode 100644 index 0000000..039b27b --- /dev/null +++ b/work_experience.go @@ -0,0 +1,45 @@ +package cvdata + +import ( + "fmt" + + utils "github.com/jesusperez/datautils" +) + +type WorkExperienceType struct { + Auth AuthInfoType `yaml:"auth" json:"auth"` + Date string `yaml:"date" json:"date"` + Where string `yaml:"where" json:"where"` + Wheredef string `yaml:"wheredef" json:"wheredef"` + Location string `yaml:"location" json:"location"` + Position string `yaml:"position" json:"position"` + Description string `yaml:"description" json:"description"` + Tools []string `yaml:"tools" json:"tools"` + Tasks []string `yaml:"tasks" json:"tasks"` +} +type WorkExperience struct { + WorkExperience []WorkExperienceType `yaml:"work_experience" json:"work_experience"` +} +type ShowWorkExperienceType struct { + Auth AuthInfoType `yaml:"auth" json:"auth"` + Date bool `yaml:"date" json:"date"` + Where bool `yaml:"where" json:"where"` + Wheredef bool `yaml:"wheredef" json:"wheredef"` + Location bool `yaml:"location" json:"location"` + Position bool `yaml:"position" json:"position"` + Description bool `yaml:"description" json:"description"` + Tools bool `yaml:"tools" json:"tools"` + Tasks bool `yaml:"tasks" json:"tasks"` +} +func (experience *WorkExperience)Load(path string) ([]WorkExperienceType, error) { + d,file,errpath := utils.DecoderFromFile(path) + if errpath != nil { + return experience.WorkExperience, errpath + } + defer file.Close() + if err := d.Decode(&experience); err != nil { + fmt.Printf("Decode: %v", err) + return experience.WorkExperience, err + } + return experience.WorkExperience, nil +}