本文整理汇总了Golang中github.com/docker/docker/engine.Env.SetJson方法的典型用法代码示例。如果您正苦于以下问题:Golang Env.SetJson方法的具体用法?Golang Env.SetJson怎么用?Golang Env.SetJson使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/docker/docker/engine.Env
的用法示例。
在下文中一共展示了Env.SetJson方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GetRegistryConfig
// GetRegistryConfig returns current registry configuration.
func (s *Service) GetRegistryConfig(job *engine.Job) engine.Status {
out := engine.Env{}
err := out.SetJson("config", s.Config)
if err != nil {
return job.Error(err)
}
out.WriteTo(job.Stdout)
return engine.StatusOK
}
示例2: GetRegistryConfig
// GetRegistryConfig returns current registry configuration.
func (s *Service) GetRegistryConfig(job *engine.Job) error {
out := engine.Env{}
err := out.SetJson("config", s.Config)
if err != nil {
return err
}
out.WriteTo(job.Stdout)
return nil
}
示例3: ResolveIndex
// ResolveIndex takes indexName and returns index info
func (s *Service) ResolveIndex(job *engine.Job) engine.Status {
var (
indexName = job.Args[0]
)
index, err := s.Config.NewIndexInfo(indexName)
if err != nil {
return job.Error(err)
}
out := engine.Env{}
err = out.SetJson("index", index)
if err != nil {
return job.Error(err)
}
out.WriteTo(job.Stdout)
return engine.StatusOK
}
示例4: ResolveRepository
// ResolveRepository splits a repository name into its components
// and configuration of the associated registry.
func (s *Service) ResolveRepository(job *engine.Job) engine.Status {
var (
reposName = job.Args[0]
)
repoInfo, err := s.Config.NewRepositoryInfo(reposName)
if err != nil {
return job.Error(err)
}
out := engine.Env{}
err = out.SetJson("repository", repoInfo)
if err != nil {
return job.Error(err)
}
out.WriteTo(job.Stdout)
return engine.StatusOK
}
示例5: TestPostContainersCgroup
func TestPostContainersCgroup(t *testing.T) {
eng := NewTestEngine(t)
defer mkDaemonFromEngine(eng, t).Nuke()
memory := int64(4194304)
containerID := createTestContainer(eng,
&runconfig.Config{
Memory: memory,
Image: unitTestImageID,
Cmd: []string{"/bin/cat"},
OpenStdin: true,
},
t,
)
defer func() {
// Make sure the process dies before destroying runtime
containerKill(eng, containerID, t)
containerWait(eng, containerID, t)
}()
startContainer(eng, containerID, t)
// Give some time to the process to start
containerWaitTimeout(eng, containerID, t)
if !containerRunning(eng, containerID, t) {
t.Errorf("Container should be running")
}
var (
cgroupData engine.Env
readSubsystem []string
writeSubsystem []struct {
Key string
Value string
}
)
readSubsystem = append(readSubsystem, "memory.limit_in_bytes")
writeSubsystem = append(writeSubsystem, struct {
Key string
Value string
}{Key: "cpu.shares", Value: "2048"})
cgroupData.SetList("ReadSubsystem", readSubsystem)
cgroupData.SetJson("WriteSubsystem", writeSubsystem)
jsonData := bytes.NewBuffer(nil)
if err := cgroupData.Encode(jsonData); err != nil {
t.Fatal(err)
}
r := httptest.NewRecorder()
req, err := http.NewRequest("POST", "/containers/"+containerID+"/cgroup?w=1", jsonData)
req.Header.Add("Content-Type", "application/json")
if err != nil {
t.Fatal(err)
}
if err := server.ServeRequest(eng, api.APIVERSION, r, req); err != nil {
t.Fatal(err)
}
assertHttpNotError(r, t)
if r.Code != http.StatusOK {
t.Fatalf("%d OK expected, received %d\n", http.StatusOK, r.Code)
}
var cgroupResponses []struct {
Subsystem string
Out string
Err string
Status int
}
if err := json.Unmarshal(r.Body.Bytes(), &cgroupResponses); err != nil {
t.Fatal(err)
}
for _, cgroupResponse := range cgroupResponses {
if cgroupResponse.Status != 0 {
t.Fatalf("The status of cgroup response is not zero, subsystem: %s, out: %s, err: %s, status: %s",
cgroupResponse.Subsystem, cgroupResponse.Out, cgroupResponse.Err, cgroupResponse.Status)
}
}
}
示例6: TestPostContainersSet
func TestPostContainersSet(t *testing.T) {
eng := NewTestEngine(t)
defer mkDaemonFromEngine(eng, t).Nuke()
memory := int64(4194304)
containerID := createTestContainer(eng,
&runconfig.Config{
Memory: memory,
Image: unitTestImageID,
Cmd: []string{"/bin/cat"},
OpenStdin: true,
},
t,
)
defer func() {
// Make sure the process dies before destroying runtime
containerKill(eng, containerID, t)
containerWait(eng, containerID, t)
}()
startContainer(eng, containerID, t)
// Give some time to the process to start
containerWaitTimeout(eng, containerID, t)
if !containerRunning(eng, containerID, t) {
t.Errorf("Container should be running")
}
var (
setData engine.Env
config []struct {
Key string
Value string
}
)
config = append(config, struct {
Key string
Value string
}{Key: "image", Value: "test:v1"})
setData.SetJson("config", config)
jsonData := bytes.NewBuffer(nil)
if err := setData.Encode(jsonData); err != nil {
t.Fatal(err)
}
r := httptest.NewRecorder()
req, err := http.NewRequest("POST", "/containers/"+containerID+"/set", jsonData)
req.Header.Add("Content-Type", "application/json")
if err != nil {
t.Fatal(err)
}
if err := server.ServeRequest(eng, api.APIVERSION, r, req); err != nil {
t.Fatal(err)
}
assertHttpNotError(r, t)
if r.Code != http.StatusOK {
t.Errorf("Expected response for OPTIONS request to be \"200\", %v found.", r.Code)
}
}