GVKun编程网logo

Golang(12)Web Service - JSON Mapping Improvement

15

如果您对Golang(12)WebService-JSONMappingImprovement感兴趣,那么本文将是一篇不错的选择,我们将为您详在本文中,您将会了解到关于Golang(12)WebSer

如果您对Golang(12)Web Service - JSON Mapping Improvement感兴趣,那么本文将是一篇不错的选择,我们将为您详在本文中,您将会了解到关于Golang(12)Web Service - JSON Mapping Improvement的详细内容,并且为您提供关于(OK) Research, implementation, and improvement of MPTCP on mobile smart devices、android – hasOverlappingRendering()和两个ImageView、Android 用 webService 产生 java.lang.ClassCastException: org.ksoap2.serialization.SoapPrimitive 错误的解决 .、com.intellij.openapi.components.impl.ServiceManagerImpl的实例源码的有价值信息。

本文目录一览:

Golang(12)Web Service - JSON Mapping Improvement

Golang(12)Web Service - JSON Mapping Improvement

Golang(12)Web Service - JSON Mapping Improvement

Take the marshal and unmarshal codes out of every method.

package main

import (
"encoding/json"
"fmt"
"github.com/gorilla/mux"
"io/IoUtil"
"net/http"
)

type Bug struct {
Id string
BugNumber string
BugName string
BugDesn string
}

type JSONResult map[string]interface{}

func (r JSONResult) String() (s string) {
b,err := json.Marshal(r)
if err != nil {
s = "json err: " + err.Error()
return
}
s = string(b)
return
}

func ParseJSON(r *http.Request) Bug {
var b Bug
c,_ := IoUtil.ReadAll(r.Body)
fmt.Println("ParseJSON called with Body=" + string(c))

json.Unmarshal(c,&b)
return b
}

func getBug(w http.ResponseWriter,r *http.Request) {
b1 := Bug{Id: "1",BugNumber: "bug1",BugName: "bug1",BugDesn: "desn1"}

w.Header().Set("Content-Type","application/json")
fmt.Fprint(w,JSONResult{"status": "ok","bugs": []Bug{b1}})
}

func updateBug(w http.ResponseWriter,r *http.Request) {
b := ParseJSON(r)

fmt.Println("updateBug called with Id=" + b.Id)
fmt.Println("updateBug called with BugNumber=" + b.BugNumber)
fmt.Println("updateBug called with BugName=" + b.BugName)
fmt.Println("updateBug called with BugDesn=" + b.BugDesn)

w.Header().Set("Content-Type","bugs": []Bug{b}})
}

func deleteBug(w http.ResponseWriter,r *http.Request) {
id := mux.Vars(r)["Id"]
fmt.Println("deleteBug called with Id = ",id)

w.Header().Set("Content-Type",JSONResult{"status": "ok"})
}

func addBug(w http.ResponseWriter,r *http.Request) {
b := ParseJSON(r)

fmt.Println("addBug called with BugNumber=" + b.BugNumber)
fmt.Println("addBug called with BugName=" + b.BugName)
fmt.Println("addBug called with BugDesn=" + b.BugDesn)

w.Header().Set("Content-Type","bugs": []Bug{b}})
}

func listBug(w http.ResponseWriter,BugDesn: "desn1"}
b2 := Bug{Id: "2",BugNumber: "bug2",BugName: "bug2",BugDesn: "desn2"}

w.Header().Set("Content-Type","bugs": []Bug{b1,b2}})
}

func main() {
router := mux.NewRouter()
router.HandleFunc("/bugs",listBug).Methods("GET")
router.HandleFunc("/bugs",addBug).Methods("POST")
router.HandleFunc("/bugs/{Id}",getBug).Methods("GET")
router.HandleFunc("/bugs/{Id}",updateBug).Methods("PUT")
router.HandleFunc("/bugs/{Id}",deleteBug).Methods("DELETE")

http.Handle("/",router)
http.ListenAndServe(":8088",nil)
}

Maybe,it will be helpful if one day I design and implement a web framework myself. Actually,it will be light and clean,only need routers,dispatcher and JSON render and parse built-in the framework.

References:
http://nesv.blogspot.com/2012/09/super-easy-json-http-responses-in-go.html
http://www.alexedwards.net/blog/golang-response-snippets#json

http://sillycat.iteye.com/blog/2056435
http://golangtutorials.blogspot.com/2011/06/methods-on-structs.html
http://stackoverflow.com/questions/18678135/go-static-method-design

(OK) Research, implementation, and improvement of MPTCP on mobile smart devices

(OK) Research, implementation, and improvement of MPTCP on mobile smart devices

download the paper: https://www.tandfonline.com/eprint/Ka6GNdE6zu9iwCvSSTu9/full

https://www.tandfonline.com/doi/full/10.1080/1206212X.2018.1455020

https://pan.baidu.com/s/1Ny3z-0_fD2eAuUjhd3Yikw


Abstract

As more and more mobile smart devices (MSDs) are equipped with multiple wireless network interfaces (e.g. WiFi, cellular, etc.), MultiPath TCP (MPTCP) can enable MSDs to send data over several interfaces or paths and can achieve better throughput and robust data transfers. MPTCP thus attracts an increasing interest from both academia and industry. This paper systematically studies MPTCP and clearly describes the relationship between each portions of MPTCP. Up to now, MPTCP has not been widely used in the mobile Internet, one of the reasons is that it is a challenge to research, implement and test MPTCP on the actual MSDs. To overcome the shortcoming of the existing researches on MPTCP being mainly limited to network simulators, a novel approach to port MPTCP to MSDs is proposed, which includes three main steps: first, run real mobile operating system (MOS) on VirtualBox; second, port MPTCP to MOS on VirtualBox and test; third, directly copy modified files in the second step to real MOS on MSD and test. By using this method, MPTCP V0.90 is successfully ported to a real smartphone running Android-7.1.1 for the first time. The validity of the method is proved by experiments. In addition, this paper improves the subpath establishment algorithm of MPTCP and applies the improved MPTCP to Mobile Ad Hoc Network (MANET) constructed by MSDs, the test result shows that our algorithm has better performance than the original MPTCP in achieving higher data throughput.

KeyWords: MPTCP, mobile smart device, VirtualBox, NS-3, Android, MANET

android – hasOverlappingRendering()和两个ImageView

android – hasOverlappingRendering()和两个ImageView

我有一个自定义视图,其中包含两个相互叠加的 ImageView.
我设置hasOverlappingRendering()返回false,并且在设置alpha时没有任何问题.

但它不是真的包含重叠渲染(两个ImageViews)吗?这不应该是某种(图形)错误吗?

解决方法

迟到的答案..但迟到总比没有好.答案是不包含重叠渲染.我发现 this video非常有用.

Google工程师正在通过示例解释当您从hasOverlappingRendering()返回false时发生的情况.

Android 用 webService 产生 java.lang.ClassCastException: org.ksoap2.serialization.SoapPrimitive 错误的解决 .

Android 用 webService 产生 java.lang.ClassCastException: org.ksoap2.serialization.SoapPrimitive 错误的解决 .

在做 android Webservice 开发的时候一般情况下大家接受 webservice 服务器返回值的时候都是使用 SoapObject soapObject = (SoapObject) envelope.getResponse (); 这个来接受返回来的值,但这种方法往往会产生 Java.lang.ClassCastException: org.ksoap2.serialization.SoapPrimitive 这样的错误。

根据本人的实际操作跟别人的帮助,终于解决了这个问题。

在服务器端返回值是 String 类型的数值的时候使用 SoapObject soapObject = (SoapObject) envelope.getResponse (); 和 SoapObject result = (SoapObject) envelope.bodyIn; 这两种方法来接受值都会报出

java.lang.ClassCastException: org.ksoap2.serialization.SoapPrimitive 这样的错误。 我们可以使用 Object object =

(Object) envelope.getResponse (); 就可以解决这种错误。 http://www.cnblogs.com/gzggyy/archive/2011/06/21/2086140.html

com.intellij.openapi.components.impl.ServiceManagerImpl的实例源码

com.intellij.openapi.components.impl.ServiceManagerImpl的实例源码

项目:intellij-ce-playground    文件:ApplicationImpl.java   
@Override
public void load(@Nullable final String configPath) {
  Accesstoken token = HeavyProcessLatch.INSTANCE.processstarted("Loading application components");
  try {
    long t = System.currentTimeMillis();
    init(mySplash == null ? null : new EmptyProgressIndicator() {
      @Override
      public void setFraction(double fraction) {
        mySplash.showProgress("",(float)(0.65 + getPercentageOfComponentsLoaded() * 0.35));
      }
    },new Runnable() {
      @Override
      public void run() {
        // create ServiceManagerImpl at first to force extension classes registration
        getpicocontainer().getComponentInstance(ServiceManagerImpl.class);

        String effectiveConfigPath = FileUtilRt.toSystemIndependentName(configPath == null ? PathManager.getConfigPath() : configPath);
        for (ApplicationLoadListener listener : ApplicationLoadListener.EP_NAME.getExtensions()) {
          try {
            listener.beforeApplicationLoaded(ApplicationImpl.this,effectiveConfigPath);
          }
          catch (Throwable e) {
            LOG.error(e);
          }
        }

        // we set it after beforeApplicationLoaded call,because app store can depends on stream provider state
        ServiceKt.getStateStore(ApplicationImpl.this).setPath(effectiveConfigPath);
      }
    });
    t = System.currentTimeMillis() - t;
    LOG.info(getComponentConfigCount() + " application components initialized in " + t + " ms");
  }
  finally {
    token.finish();
  }
  myLoaded = true;

  createLocatorFile();
}
项目:intellij-ce-playground    文件:FocusManagerImpl.java   
@SuppressWarnings("UnusedParameters")  // the dependencies are needed to ensure correct loading order
public FocusManagerImpl(ServiceManagerImpl serviceManager,WindowManager wm,UiActivityMonitor monitor) {
  myApp = ApplicationManager.getApplication();
  myQueue = IdeEventQueue.getInstance();
  myActivityMonitor = monitor;

  myFocusedComponentAlarm = new EdtAlarm();
  myForcedFocusRequestsAlarm = new EdtAlarm();
  myIdleAlarm = new EdtAlarm();

  final AppListener myAppListener = new AppListener();
  myApp.getMessageBus().connect().subscribe(ApplicationActivationListener.TOPIC,myAppListener);

  IdeEventQueue.getInstance().adddispatcher(new IdeEventQueue.Eventdispatcher() {
    @Override
    public boolean dispatch(AWTEvent e) {
      if (e instanceof FocusEvent) {
        final FocusEvent fe = (FocusEvent)e;
        final Component c = fe.getComponent();
        if (c instanceof Window || c == null) return false;

        Component parent = UIUtil.findUltimateParent(c);

        if (parent instanceof IdeFrame) {
          myLastFocused.put((IdeFrame)parent,c);
        }
      }
      else if (e instanceof WindowEvent) {
        Window wnd = ((WindowEvent)e).getwindow();
        if (e.getID() == WindowEvent.WINDOW_CLOSED) {
          if (wnd instanceof IdeFrame) {
            myLastFocused.remove(wnd);
            myLastFocusedAtDeactivation.remove(wnd);
          }
        }
      }

      return false;
    }
  },this);

  KeyboardFocusManager.getCurrentKeyboardFocusManager().addPropertychangelistener("focusedWindow",new Propertychangelistener() {
    @Override
    public void propertyChange(PropertyChangeEvent evt) {
      if (evt.getNewValue() instanceof IdeFrame) {
        myLastFocusedFrame = (IdeFrame)evt.getNewValue();
      }
    }
  });
}
项目:tools-idea    文件:FocusManagerImpl.java   
@SuppressWarnings("UnusedParameters")  // the dependencies are needed to ensure correct loading order
public FocusManagerImpl(ServiceManagerImpl serviceManager,UiActivityMonitor monitor) {
  myApp = ApplicationManager.getApplication();
  myQueue = IdeEventQueue.getInstance();
  myActivityMonitor = monitor;

  myFocusedComponentAlaram = new EdtAlarm();
  myForcedFocusRequestsAlarm = new EdtAlarm();
  myIdleAlarm = new EdtAlarm();

  final AppListener myAppListener = new AppListener();
  myApp.getMessageBus().connect().subscribe(ApplicationActivationListener.TOPIC,myAppListener);

  IdeEventQueue.getInstance().adddispatcher(new IdeEventQueue.Eventdispatcher() {
    public boolean dispatch(AWTEvent e) {
      if (e instanceof FocusEvent) {
        final FocusEvent fe = (FocusEvent)e;
        final Component c = fe.getComponent();
        if (c instanceof Window || c == null) return false;

        Component parent = SwingUtilities.getwindowAncestor(c);

        if (parent instanceof IdeFrame) {
          myLastFocused.put((IdeFrame)parent,new WeakReference<Component>(c));
        }
      } else if (e instanceof WindowEvent) {
        Window wnd = ((WindowEvent)e).getwindow();
        if (e.getID() == WindowEvent.WINDOW_CLOSED) {
          if (wnd instanceof IdeFrame) {
            myLastFocused.remove((IdeFrame)wnd);
            myLastFocusedAtDeactivation.remove((IdeFrame)wnd);
          }
        }
      }

      return false;
    }
  },new Propertychangelistener() {
    @Override
    public void propertyChange(PropertyChangeEvent evt) {
      if (evt.getNewValue() instanceof IdeFrame) {
        myLastFocusedFrame = (IdeFrame)evt.getNewValue();
      }
    }
  });
}
项目:consulo    文件:FocusManagerImpl.java   
@SuppressWarnings("UnusedParameters")  // the dependencies are needed to ensure correct loading order
public FocusManagerImpl(ServiceManagerImpl serviceManager,UiActivityMonitor monitor) {
  myApp = ApplicationManager.getApplication();
  myQueue = IdeEventQueue.getInstance();
  myActivityMonitor = monitor;

  myFocusedComponentAlarm = new EdtAlarm();
  myForcedFocusRequestsAlarm = new EdtAlarm();

  final AppListener myAppListener = new AppListener();
  myApp.getMessageBus().connect().subscribe(ApplicationActivationListener.TOPIC,myAppListener);

  IdeEventQueue.getInstance().adddispatcher(e -> {
    if (e instanceof FocusEvent) {
      final FocusEvent fe = (FocusEvent)e;
      final Component c = fe.getComponent();
      if (c instanceof Window || c == null) return false;

      Component parent = UIUtil.findUltimateParent(c);

      if (parent instanceof IdeFrame) {
        myLastFocused.put((IdeFrame)parent,c);
      }
    }
    else if (e instanceof WindowEvent) {
      Window wnd = ((WindowEvent)e).getwindow();
      if (e.getID() == WindowEvent.WINDOW_CLOSED) {
        if (wnd instanceof IdeFrame) {
          myLastFocused.remove(wnd);
          myLastFocusedAtDeactivation.remove(wnd);
        }
      }
    }

    return false;
  },new Propertychangelistener() {
    @Override
    public void propertyChange(PropertyChangeEvent evt) {
      if (evt.getNewValue() instanceof IdeFrame) {
        myLastFocusedFrame = (IdeFrame)evt.getNewValue();
      }
    }
  });
}
项目:consulo    文件:ExportSettingsAction.java   
@Nonnull
public static MultiMap<File,ExportableItem> getExportableComponentsMap(final boolean onlyExisting) {
  final MultiMap<File,ExportableItem> result = MultiMap.createLinkedSet();

  ApplicationImpl application = (ApplicationImpl)ApplicationManager.getApplication();
  final StateStorageManager storageManager = application.getStateStore().getStateStorageManager();
  ServiceManagerImpl.processAllImplementationClasses(application,(aClass,pluginDescriptor) -> {
    State stateAnnotation = aClass.getAnnotation(State.class);
    if (stateAnnotation != null && !StringUtil.isEmpty(stateAnnotation.name())) {
      int storageIndex;
      Storage[] storages = stateAnnotation.storages();
      if (storages.length == 1) {
        storageIndex = 0;
      }
      else if (storages.length > 1) {
        storageIndex = storages.length - 1;
      }
      else {
        return true;
      }

      Storage storage = storages[storageIndex];
      if (storage.roamingType() != RoamingType.disABLED) {
        String fileSpec = storageManager.buildFileSpec(storage);

        if (!fileSpec.startsWith(StoragePathMacros.APP_CONfig)) {
          return true;
        }

        File file = new File(storageManager.expandMacros(fileSpec));

        File additionalExportFile = null;
        if (!StringUtil.isEmpty(stateAnnotation.additionalExportFile())) {
          additionalExportFile = new File(storageManager.expandMacros(stateAnnotation.additionalExportFile()));
          if (onlyExisting && !additionalExportFile.exists()) {
            additionalExportFile = null;
          }
        }

        boolean fileExists = !onlyExisting || file.exists();
        if (fileExists || additionalExportFile != null) {
          File[] files;
          if (additionalExportFile == null) {
            files = new File[]{file};
          }
          else {
            files = fileExists ? new File[]{file,additionalExportFile} : new File[]{additionalExportFile};
          }
          ExportableItem item = new ExportableItem(files,getComponentPresentableName(stateAnnotation,aClass,pluginDescriptor));
          result.putValue(file,item);
          if (additionalExportFile != null) {
            result.putValue(additionalExportFile,item);
          }
        }
      }
    }
    return true;
  });
  return result;
}

我们今天的关于Golang(12)Web Service - JSON Mapping Improvement的分享就到这里,谢谢您的阅读,如果想了解更多关于(OK) Research, implementation, and improvement of MPTCP on mobile smart devices、android – hasOverlappingRendering()和两个ImageView、Android 用 webService 产生 java.lang.ClassCastException: org.ksoap2.serialization.SoapPrimitive 错误的解决 .、com.intellij.openapi.components.impl.ServiceManagerImpl的实例源码的相关信息,可以在本站进行搜索。

本文标签: