github.com/Xenoex/gopm@v0.6.5/cmd/service.go (about) 1 // Copyright 2013 gopm authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"): you may 4 // not use this file except in compliance with the License. You may obtain 5 // a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 // License for the specific language governing permissions and limitations 13 // under the License. 14 15 package cmd 16 17 // func getService(pkgName string) Service { 18 // for _, service := range services { 19 // if service.HasPkg(pkgName) { 20 // return service 21 // } 22 // } 23 // return nil 24 // } 25 26 // type Service interface { 27 // PkgUrl(pkg *Pkg) string 28 // HasPkg(pkgName string) bool 29 // PkgExt() string 30 // } 31 32 //type Pkg struct { 33 // Name string 34 // Ver string 35 // VerId string 36 //} 37 38 // func NewPkg(pkgName string, ver string) *Pkg { 39 // vers := strings.Split(ver, ":") 40 // if len(vers) > 2 { 41 // return nil 42 // } 43 44 // var verId string 45 // if len(vers) == 2 { 46 // verId = vers[1] 47 // } 48 49 // if len(vers) == 1 { 50 // vers[0] = TRUNK 51 // } 52 53 // service := getService(pkgName) 54 // if service == nil { 55 // return nil 56 // } 57 58 // return &Pkg{service, pkgName, vers[0], verId} 59 // } 60 61 // func (p *Pkg) VerSimpleString() string { 62 // if p.VerId != "" { 63 // return p.VerId 64 // } 65 // return p.Ver 66 // } 67 68 // func (p *Pkg) Url() string { 69 // return p.Service.PkgUrl(p) 70 // } 71 72 // func (p *Pkg) FileName() string { 73 // return fmt.Sprintf("%v.%v", p.VerSimpleString(), p.Service.PkgExt()) 74 // } 75 76 // // github repository 77 // type GithubService struct { 78 // } 79 80 // func (s *GithubService) PkgUrl(pkg *Pkg) string { 81 // var verPath string 82 // if pkg.Ver == TRUNK { 83 // verPath = "master" 84 // } else { 85 // verPath = pkg.VerId 86 // } 87 // return fmt.Sprintf("https://%v/archive/%v.zip", pkg.Name, verPath) 88 // } 89 90 // func (s *GithubService) HasPkg(pkgName string) bool { 91 // return strings.HasPrefix(pkgName, "github.com") 92 // } 93 94 // func (s *GithubService) PkgExt() string { 95 // return "zip" 96 // } 97 98 // // git osc repos 99 // type GitOscService struct { 100 // } 101 102 // func (s *GitOscService) PkgUrl(pkg *Pkg) string { 103 // var verPath string 104 // if pkg.Ver == TRUNK { 105 // verPath = "master" 106 // } else { 107 // verPath = pkg.VerId 108 // } 109 // return fmt.Sprintf("https://%v/repository/archive?ref=%v", pkg.Name, verPath) 110 // } 111 112 // func (s *GitOscService) HasPkg(pkgName string) bool { 113 // return strings.HasPrefix(pkgName, "git.oschina.net") 114 // } 115 116 // func (s *GitOscService) PkgExt() string { 117 // return "zip" 118 // } 119 120 // // bitbucket.org 121 // type BitBucketService struct { 122 // } 123 124 // func (s *BitBucketService) PkgUrl(pkg *Pkg) string { 125 // var verPath string 126 // if pkg.Ver == TRUNK { 127 // verPath = "default" 128 // } else { 129 // verPath = pkg.VerId 130 // } 131 132 // return fmt.Sprintf("https://%v/get/%v.zip", pkg.Name, verPath) 133 // } 134 135 // func (s *BitBucketService) HasPkg(pkgName string) bool { 136 // return strings.HasPrefix(pkgName, "bitbucket.org") 137 // } 138 139 // func (s *BitBucketService) PkgExt() string { 140 // return "zip" 141 // } 142 143 // type GitCafeService struct { 144 // } 145 146 // func (s *GitCafeService) PkgUrl(pkg *Pkg) string { 147 // var verPath string 148 // if pkg.Ver == TRUNK { 149 // verPath = "master" 150 // } else { 151 // verPath = pkg.VerId 152 // } 153 154 // return fmt.Sprintf("https://%v/tarball/%v", pkg.Name, verPath) 155 // } 156 157 // func (s *GitCafeService) HasPkg(pkgName string) bool { 158 // return strings.HasPrefix(pkgName, "gitcafe.com") 159 // } 160 161 // func (s *GitCafeService) PkgExt() string { 162 // return "tar.gz" 163 // } 164 165 // // git lab repos, not completed 166 // type GitLabService struct { 167 // DomainOrIp string 168 // Username string 169 // Passwd string 170 // PrivateKey string 171 // } 172 173 // func (s *GitLabService) PkgUrl(pkg *Pkg) string { 174 // var verPath string 175 // if pkg.Ver == TRUNK { 176 // verPath = "master" 177 // } else { 178 // verPath = pkg.VerId 179 // } 180 181 // return fmt.Sprintf("https://%v/repository/archive/%v", pkg.Name, verPath) 182 // } 183 184 // func (s *GitLabService) HasPkg(pkgName string) bool { 185 // return strings.HasPrefix(pkgName, s.DomainOrIp) 186 // } 187 188 // func (s *GitLabService) PkgExt() string { 189 // return "tar.gz" 190 // } 191 192 // // code.csdn.net 193 // type CodeCSDNService struct { 194 // } 195 196 // func (s *CodeCSDNService) PkgUrl(pkg *Pkg) string { 197 // var verPath string 198 // if pkg.Ver == TRUNK { 199 // verPath = "master" 200 // } else { 201 // verPath = pkg.VerId 202 // } 203 204 // return fmt.Sprintf("https://%v/repository/archive?ref=%v", pkg.Name, verPath) 205 // } 206 207 // func (s *CodeCSDNService) HasPkg(pkgName string) bool { 208 // return strings.HasPrefix(pkgName, "code.csdn.net") 209 // } 210 211 // func (s *CodeCSDNService) PkgExt() string { 212 // return "zip" 213 // }